How to print a List of Arrays (with elements) using Java 8 Streams? -


this question has answer here:

public static void main(string[] args) {     list<integer> numbers1 = arrays.aslist(1,2,3);     list<integer> numbers2 = arrays.aslist(3,4);      list<int[]> intpairs = numbers1.stream()             .flatmap(i -> numbers2.stream()                     .filter(j -> (i+j)%3 == 0)                     .map(j -> new int[]{i,j}))                     .collect(collectors.tolist());      intpairs.stream().foreach(system.out::println); } 

for above code, getting output as:

[i@214c265e [i@448139f0 

but expectation [(2, 4), (3, 3)].

could please guide me achieve this?

you can change mapping part list instead of using int[]:

.... .map(j -> arrays.aslist(i,j))) .... 

and output following:

[2, 4] [3, 3] 

here complete example:

public static void main(string[] args) {     list<integer> numbers1 = arrays.aslist(1,2,3);     list<integer> numbers2 = arrays.aslist(3,4);      list<list<integer>> intpairs = numbers1.stream()             .flatmap(i -> numbers2.stream()                     .filter(j -> (i+j)%3 == 0)                     .map(j -> arrays.aslist(i,j)))                     .collect(collectors.tolist());     intpairs.stream().foreach(system.out::println); } 

hope helps.


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -