Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save simonwoo/07ce7bc4160c9338ddfc to your computer and use it in GitHub Desktop.

Select an option

Save simonwoo/07ce7bc4160c9338ddfc to your computer and use it in GitHub Desktop.
public static Set<String> findDuplicates(List<String> listContainingDuplicates) {
	final Set<String> setToReturn = new HashSet<String>();
	final Set<String> set1 = new HashSet<String>();

	for (String yourInt : listContainingDuplicates) {
		if (!set1.add(yourInt)) {
			setToReturn.add(yourInt);
		}
	}
	return setToReturn;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment