I am trying to prevent duplicate entries from being added to an ArrayList as the list is being populated whilst reading through each line of a file. Each line of the file is
ArrayList ar=new ArrayList();
String a[]={"cat","bat","cat","knife"};
for(int i=0;i
Create an array list, and check whether it contains the string to be inserted. If it does not contain the string, then you can add it into the array list. This way you can avoid the duplicate entries in the array list.
The elements in the array list for the above code would be
cat
bat
knife