mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 15:27:45 +07:00
IDEA-166211 Convert for-loop with Collections.addAll inside into Java 8's stream API calls chain
This commit is contained in:
+8
@@ -0,0 +1,8 @@
|
||||
// "Replace with toArray" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Test {
|
||||
Object[] test(List<String[]> list) {
|
||||
return list.stream().filter(Objects::nonNull).flatMap(Arrays::stream).sorted().toArray();
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace with toArray" "true"
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
Object[] test(List<String> list) {
|
||||
return list.stream().filter(Objects::nonNull).flatMap(str -> Stream.of(str, str + str)).sorted().toArray();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Arrays.toString(new Test().test(Arrays.asList("a", "b", "ba", "x", null, "c"))));
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace with toArray" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Test {
|
||||
Object[] test(List<String[]> list) {
|
||||
List<Object> result = new LinkedList<>();
|
||||
for(String[] str : li<caret>st) {
|
||||
if(str != null) {
|
||||
Collections.addAll(result, str);
|
||||
}
|
||||
}
|
||||
result.sort(null);
|
||||
return result.toArray();
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace with toArray" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Test {
|
||||
Object[] test(List<String> list) {
|
||||
List<Object> result = new LinkedList<>();
|
||||
for(String str : lis<caret>t) {
|
||||
if(str != null) {
|
||||
Collections.addAll(result, str, str+str);
|
||||
}
|
||||
}
|
||||
result.sort(null);
|
||||
return result.toArray();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Arrays.toString(new Test().test(Arrays.asList("a", "b", "ba", "x", null, "c"))));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user