mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-10 09:39:37 +07:00
add new groupBy cases
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
// "Replace with collect" "true"
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
private Map<Integer, List<String>> test(String... list) {
|
||||
Map<Integer, List<String>> map = Arrays.stream(list).filter(Objects::nonNull).collect(Collectors.groupingBy(String::length));
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(new Main().test("a", "bbb", null, "cc", "dd", "eedasfasdfs", "dd"));
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,8 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
private Map<Integer, List<String>> test(String... list) {
|
||||
Map<Integer, List<String>> map = new HashMap<>();
|
||||
map = Arrays.stream(list).filter(Objects::nonNull).collect(Collectors.groupingBy(String::length, Collectors.toCollection(ArrayList::new)));
|
||||
return map;
|
||||
Map<Integer, List<String>> map = Arrays.stream(list).filter(Objects::nonNull).collect(Collectors.groupingBy(String::length));
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// "Replace with collect" "true"
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
Map<Integer, List<String>> test(List<String> list) {
|
||||
Map<Integer, List<String>> map = list.stream().collect(Collectors.groupingBy(String::length));
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(new Main().test("a", "bbb", null, "cc", "dd", "eedasfasdfs", "dd"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// "Replace with collect" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
private Map<Integer, List<String>> test(String... list) {
|
||||
Map<Integer, List<String>> map = new HashMap<>();
|
||||
for(String s : li<caret>st) {
|
||||
if(s != null) {
|
||||
List<String> tmp = map.get(s.length());
|
||||
if(tmp == null) map.put(s.length(), tmp = new ArrayList<>());
|
||||
tmp.add(s);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(new Main().test("a", "bbb", null, "cc", "dd", "eedasfasdfs", "dd"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// "Replace with collect" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
Map<Integer, List<String>> test(List<String> list) {
|
||||
Map<Integer, List<String>> map = new HashMap<>();
|
||||
for<caret> (String s : list) {
|
||||
List<String> strings = map.computeIfAbsent(s.length(), k -> new ArrayList<>());
|
||||
strings.add(s);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(new Main().test("a", "bbb", null, "cc", "dd", "eedasfasdfs", "dd"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user