mardi 21 mai 2019

How to find Distinct value in 2-D Array using Stream component in Java

i want to iterate 2-D array and find distinct value in 2-D Array in Java using Stream (Java 1.8). i tried the below code. when i print the value. it is not in printed format.

i tried the below code.

int mat[][] = { { 1, 2, 3 }, { 4, 5, 5 }, { 7, 6, 3 } }; Arrays.stream(mat).forEach(x -> System.out.println(x)); i used Distinct method from stream component. but still it is not printing readable format.

Expected : i was thinking. i will get distinct values from 2-D Array. 1,2,3,4,5,6,7 Actual : i was getting unreadable format Answer. output:

I could not place Out it is not readable format

Aucun commentaire:

Enregistrer un commentaire