Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- SelectApp app = new SelectApp();
- app.process();
- }
- private void process() {
- int[] input = {1, 2, 5, 1, 2, 4, 1, 2, 3, 3};
- Set<Integer> element = elementWithoutDuplicate(input);
- System.out.println("element: " + element);
- }
- private Set<Integer> elementWithoutDuplicate(int[] input) {
- List<Integer> coll = Arrays.stream(input).boxed().collect(Collectors.toList());
- Map<Integer, Long> map = coll.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
- return map.entrySet().stream().filter(entry -> entry.getValue() == 1).map(Map.Entry::getKey).collect(Collectors.toSet());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement