Consider a text file of IDs, with one ID per line, which has duplicate IDs. We would like to eliminate the duplicate IDs by using an ArrayList. Read each ID from the file, add it to the ArrayList if it is not already added, and then output all IDs in the ArrayList to a new text file..
i solved it that i will add all the id and then cheek if they exist and remove them however my doctor did not want them to be add in the first place
ArrayList<Integer> myid = new ArrayList<Integer>();
int idset,count=14;
while(sc.hasNextInt()) {
idset = sc.nextInt();
myid.add(idset);
}
for (int i = 1; i < myid.size(); i++) {
int a1 = (int) myid.get(i);
int a2 = (int) myid.get(i-1);
if (a1 != a2) {
count--;
}
else {
myid.remove(a1);
}
}
pw.println(myid);
pw.println("duplicate = "+count);