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

This commit is contained in:
Tagir Valeev
2016-11-24 17:46:45 +07:00
parent 16469a3b99
commit c2e815fc97
86 changed files with 2019 additions and 206 deletions

View File

@@ -0,0 +1,21 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Main {
public static Map<Integer, String> test(List<String> strings) {
Map<Integer, String> map = new HashMap<>();
for (String str : strings) {
if (map.put(str.length(), str) != null) {
throw new IllegalStateException("Duplicate key");
}
}
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", "")));
}
}