mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 00:11:26 +07:00
convert to streams: convert lambda to constructor reference; don't accept list when arrayList expected
This commit is contained in:
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace with collect" "true"
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class A {
|
||||
public static void main(List<String> args) {
|
||||
ArrayList<String> uniqNames = args.stream().map(name -> name.substring(1)).collect(Collectors.toCollection(ArrayList::new));
|
||||
uniqNames.forEach(System.out::println);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+1
-1
@@ -10,6 +10,6 @@ public class Collect {
|
||||
}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
Set<String> names = persons.stream().map(Person::getName).collect(Collectors.toCollection(() -> new LinkedHashSet<>()));
|
||||
Set<String> names = persons.stream().map(Person::getName).collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
}
|
||||
}
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace with collect" "true"
|
||||
import java.util.*;
|
||||
|
||||
class A {
|
||||
public static void main(List<String> args) {
|
||||
ArrayList<String> uniqNames = new ArrayList<>();
|
||||
for (String name : ar<caret>gs){
|
||||
uniqNames.add(name.substring(1));
|
||||
}
|
||||
uniqNames.forEach(System.out::println);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user