java - Prevent duplicate values in an array -


how can ask user reenter again if value pid existed in array ?

ex: enter b , enter again, entered last not accepted because it's existed.

int[] process = {}; int numberofprocess = 0;   string[] pid = new string[10]; //proces id   system.out.print("enter number of process 1 10 : ");     while(berror){         if(scan.hasnextint()){             numberofprocess = scan.nextint();         }else{               scan.next();             continue;         }             berror = false;      } //----------------  ask user input process id @ , ex -------  for(int i=0;numberofprocess > i;i++){      system.out.print("please enter processid " + (i + 1) + " : ");         pid[i] = scan.next();   } 

i'd not use array linkedhashset (assuming want preserve input order). check using set's contains(...) method or try add pid using add(...) , check return value (false if has not been added, i.e. if existed in set).


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -