// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true" import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; public class Main { private List asList(CharSequence s) { return Collections.singletonList(s); } public List getListExtends() { return Collections.emptyList(); } public List getList() { return Collections.emptyList(); } private void collect() { List res = getListExtends().stream().filter(Objects::nonNull).collect(Collectors.toList()); System.out.println(res); } private void collect2() { List> res2 = getListExtends().stream().map(this::asList).collect(Collectors.toList()); System.out.println(res2); } static class MyList extends ArrayList> { } private void collectCustomList() { MyList> res2 = getListExtends().stream().map(this::asList).collect(Collectors.toCollection(MyList::new)); System.out.println(res2); } static class MyList2 extends ArrayList { } public MyList2 createMyList2() { return new MyList2<>(); } private void collectGroupingByCustomList() { Map> map = getList().stream().collect(Collectors.groupingBy(x -> x.length(), Collectors.toCollection(this::createMyList2))); System.out.println(map); } private void collectToMap() { Map> map = getList() .stream().filter(Objects::nonNull).collect(Collectors.toMap(Function.identity(), this::asList)); System.out.println(map); } }