IDEA-163405 Migration from Stream API back to for loops: iteration#2

This commit is contained in:
Tagir Valeev
2016-11-24 18:15:51 +07:00
parent 16469a3b99
commit c2e815fc97
86 changed files with 2019 additions and 206 deletions
@@ -0,0 +1,19 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Main {
public static Map<Integer, List<String>> test(List<String> strings) {
Map<Integer, List<String>> map = new HashMap<>();
for (String str : strings) {
map.computeIfAbsent(str.length(), k -> new ArrayList<>()).add(str);
}
return map;
}
public static void main(String[] args) {
System.out.println(test(Arrays.asList()));
System.out.println(test(Arrays.asList("a", "bbb", "cc", "d", "eee")));
}
}