mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-25 14:25:04 +07:00
StreamToLoop: merge sorted().toArray() and sorted().collect(Collectors.toList()) into single step
This commit is contained in:
+2
-6
@@ -5,15 +5,11 @@ import java.util.stream.*;
|
||||
|
||||
public class Main {
|
||||
public List<String> testSorted(List<String> list) {
|
||||
List<String> toSort = new ArrayList<>();
|
||||
for (String s : list) {
|
||||
toSort.add(s);
|
||||
}
|
||||
toSort.sort(String.CASE_INSENSITIVE_ORDER);
|
||||
List<String> result = new ArrayList<>();
|
||||
for (String s : toSort) {
|
||||
for (String s : list) {
|
||||
result.add(s);
|
||||
}
|
||||
result.sort(String.CASE_INSENSITIVE_ORDER);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.*;
|
||||
|
||||
public class Main {
|
||||
public List<String> testSorted(List<String> list) {
|
||||
List<String> result = new ArrayList<>();
|
||||
for (String s : list) {
|
||||
result.add(s);
|
||||
}
|
||||
result.sort(null);
|
||||
return result.toArray(new String[0]);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.*;
|
||||
|
||||
public class Main {
|
||||
public List<String> testSorted(List<String> list) {
|
||||
return list.stream().sorted().<caret>toArray(String[]::new);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user