File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
src/com/xpinjection/java8/misused/stream Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .xpinjection .java8 .misused .stream ;
2+
3+ import com .xpinjection .java8 .misused .Annotations .Good ;
4+ import com .xpinjection .java8 .misused .Annotations .Ugly ;
5+ import com .xpinjection .java8 .misused .User ;
6+
7+ import java .util .List ;
8+ import java .util .stream .Collectors ;
9+
10+ public class StreamMayBeConvertedToArray {
11+ @ Ugly
12+ class ConvertToArrayViaList {
13+ public String [] getUserNames (List <User > users ) {
14+ List <String > names = users .stream ()
15+ .map (User ::getName )
16+ .collect (Collectors .toList ());
17+ return names .toArray (new String [names .size ()]);
18+ }
19+ }
20+
21+ @ Good
22+ class ConvertToArrayDirectly {
23+ public String [] getUserNames (List <User > users ) {
24+ return users .stream ()
25+ .map (User ::getName )
26+ .toArray (String []::new );
27+ }
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments