Created
August 25, 2012 18:08
-
-
Save uttesh/3468678 to your computer and use it in GitHub Desktop.
Find Number of duplicates present in a ArrayList
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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