Set<Long> set = new LinkedHashSet<>(); set.iterator().next(); // LinkedHashSet guarantees insertion order