mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 03:13:40 +07:00
StreamToLoop/ToPrimitiveArrayTerminalOperation: reassign final array making it possible to reuse existing variable
This commit is contained in:
+2
-1
@@ -13,7 +13,8 @@ public class Main {
|
||||
arr[count++] = x;
|
||||
}
|
||||
}
|
||||
return Arrays.copyOfRange(arr, 0, count);
|
||||
arr = Arrays.copyOfRange(arr, 0, count);
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public int[] testPrimitive(List<String> list) {
|
||||
List<String> toSort = new ArrayList<>();
|
||||
for (String s : list) {
|
||||
toSort.add(s);
|
||||
}
|
||||
toSort.sort(null);
|
||||
int[] ints = new int[10];
|
||||
int count = 0;
|
||||
for (String s : toSort) {
|
||||
int length = s.length();
|
||||
if (ints.length == count) ints = Arrays.copyOf(ints, count * 2);
|
||||
ints[count++] = length;
|
||||
}
|
||||
ints = Arrays.copyOfRange(ints, 0, count);
|
||||
return ints;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Arrays
|
||||
.toString(new Main().testPrimitive(asList("sdfg", "asd", "sdgfdsg", "adas", "asgfsgf", "werrew"))));
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public int[] testPrimitive(List<String> list) {
|
||||
int[] ints = list.stream().sorted().mapToInt(String::length).<caret>toArray();
|
||||
return ints;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Arrays
|
||||
.toString(new Main().testPrimitive(asList("sdfg", "asd", "sdgfdsg", "adas", "asgfsgf", "werrew"))));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user