Answer the question
In order to leave comments, you need to log in
How to translate the following code into stream in Java 8?
Hello, I have the following code:
Set<Team> teams = new HashSet<>();
for (Team team : scenario.getTeamsActive()) {
for (UserAsLearner userAsLearner : learners) {
if(team.getLearners().contains(userAsLearner)) {
teams.add(team);
break;
}
}
}
Answer the question
In order to leave comments, you need to log in
Senior Devosaur **totally **no time to do it for you here is a simple example to start with
List<String> OSes = Arrays
.asList(new String[] { "windows", "dos", "mac", "linux" });
Map<String, String> defaultBrowsers = new HashMap<>();
defaultBrowsers.put("windows", "Chrome");
defaultBrowsers.put("linux", "Firefox");
defaultBrowsers.put("mac", "Safari");
List<String> result = OSes.stream().filter(o -> {
return (defaultBrowsers.containsKey(o)) ? true : false;
}).collect(Collectors.toList());
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question