convert to streams: convert lambda to constructor reference; don't accept list when arrayList expected

This commit is contained in:
Anna Kozlova
2015-06-09 20:31:02 +03:00
parent 46173543d5
commit 155f283f0e
4 changed files with 42 additions and 6 deletions
@@ -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);
}
}
@@ -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));
}
}
@@ -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);
}
}