About Question enthuware.ocpjp.v11.2.1773 :
Posted: Sat Mar 20, 2021 5:03 am
HMMM... played in all that stuff in ide and found strange thing
for example
List<String> l1 = Arrays.asList("a", "b");
List<String> l2 = Arrays.asList("1", "2");
Stream.of(l1).flatMap((x)->Stream.of(x)).forEach((x)->System.out.println(x));
Stream.of(l1, l2).flatMap((x)->Stream.of(x)).forEach((x)->System.out.println(x));
with lists - if we add more lists in method .of we will get more elements in the stream
int[][] i ={{1,2},{3,4},{5,6}};
Stream.of(i).forEach((y)->System.out.println(Arrays.toString(y)));
Stream.of(i,i).forEach((y)->System.out.println(Arrays.toString(y)));
but with array if we add 2 arrays instead of one we will get 2 elements in stream instead of 3.
Method Stream.of works different when it has one array ?
So it works like more like Arrays.stream.(i) if there is one array element
BUT!!!! If SO, why than .flatMap(x-> Stream.of(x)) and .flatMapToInt(x-> Arrays.stream(x)) inside of the same stream works differently????
for example
List<String> l1 = Arrays.asList("a", "b");
List<String> l2 = Arrays.asList("1", "2");
Stream.of(l1).flatMap((x)->Stream.of(x)).forEach((x)->System.out.println(x));
Stream.of(l1, l2).flatMap((x)->Stream.of(x)).forEach((x)->System.out.println(x));
with lists - if we add more lists in method .of we will get more elements in the stream
int[][] i ={{1,2},{3,4},{5,6}};
Stream.of(i).forEach((y)->System.out.println(Arrays.toString(y)));
Stream.of(i,i).forEach((y)->System.out.println(Arrays.toString(y)));
but with array if we add 2 arrays instead of one we will get 2 elements in stream instead of 3.
Method Stream.of works different when it has one array ?
So it works like more like Arrays.stream.(i) if there is one array element
BUT!!!! If SO, why than .flatMap(x-> Stream.of(x)) and .flatMapToInt(x-> Arrays.stream(x)) inside of the same stream works differently????