Created
August 13, 2019 14:05
-
-
Save patricksan/b26c564c43d36f1ce30cde646444d59b to your computer and use it in GitHub Desktop.
Discovery which itens are not duplicated
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.moogu.restore; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Collections; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
import java.util.stream.Stream; | |
public class LessPerformanceApproach { | |
public static void main(String[] args) { | |
List<String> letters = Arrays.asList("a", "b", "c", "d", "e", "f", "g", "f", "e", "c", "b"); | |
LessPerformanceApproach main = new LessPerformanceApproach(); | |
System.out.println(main.processStream(letters.stream())); | |
} | |
private List<String> processStream(Stream<String> stream) { | |
List<String> result = new ArrayList<>(); | |
List<String> allValues = stream.collect(Collectors.toList()); | |
for (String value : allValues) { | |
if (Collections.frequency(allValues, value) == 1) { | |
result.add(value); | |
} | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment