How to prevent duplicates in array?


Im trying to make a program where you cant add a new employe with the same ID that is already taken. But with this code it adds the employe anyways. Any suggestions to how I can change my code?

Also the array is supposed to hold a maximum of 20 employees.

I´ll gladly provide any more information if needed. Thank you.

for(Employe employe : employeArr) { 

if(employe != null && employe.getEmployeID().equals(eID)) { 

counter = employeArr.length-1; 
System.out.println("An employe with " + eID + " is already in your 
collection"); 
                
}

else if (counter<20) {  
employeArr(counter) = e_obj;
counter++; 
} 
else { 
System.out.println("The array is full.");
counter = employeArr.length-1;