Java: Detect duplicates in ArrayList?
Simplest: dump the whole collection into a Set (using the Set(Collection) constructor or Set.addAll), then see if the Set has the same size as the ArrayList. List<Integer> list = …; Set<Integer> set = new HashSet<Integer>(list); if(set.size() < list.size()){ /* There are duplicates */ } Update: If I’m understanding your question correctly, you have a 2d … Read more