// Uses a set, which does not allow duplicates for (String name : names) { if (set.add(name) == false) { // print name your duplicate element } }