Java tutorial
//package com.java2s; import java.util.LinkedHashSet; import java.util.Set; public class Main { private static Integer _findDuplicate(int[] array) { Set<Integer> seenElements = new LinkedHashSet<>(); for (int element : array) { if (!seenElements.add(element)) { return element; } } return null; } }