Skip to content

Instantly share code, notes, and snippets.

@uttesh
Created August 25, 2012 18:08
Show Gist options
  • Save uttesh/3468678 to your computer and use it in GitHub Desktop.
Save uttesh/3468678 to your computer and use it in GitHub Desktop.
Find Number of duplicates present in a ArrayList
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
list.add(67);
list.add(32);
list.add(6);
list.add(4);
list.add(67);
list.add(3);
list.add(6);
list.add(2);
list.add(6);
list.add(2);
list.add(67);
list.add(6);
list.add(4);
Set<Integer> filterList = new HashSet<Integer>(list);
Iterator<Integer> iterator = filterList.iterator();
while(iterator.hasNext()){
int number = iterator.next();
int occurrence = Collections.frequency(list, number);
System.out.println("| Number \t"+number+"\t| occures : \t"+occurrence+" Times |");
System.out.println(" ------------------------------------------------");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment