StreamToLoop: merge sorted().toArray() and sorted().collect(Collectors.toList()) into single step

This commit is contained in:
Tagir Valeev
2016-12-27 17:47:44 +07:00
parent 4305f611dc
commit d707262f9d
5 changed files with 129 additions and 46 deletions
@@ -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;
}
}
@@ -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]);
}
}
@@ -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);
}
}