Consider this two dimensional array
String[][] names = { {"Sam", "Smith"}, {"Robert", "Delgro"}, {"James", "Gosling"}, };
Using the classical method, if we want to access each element of a two-dimensional array, we need to iterate through the two-dimensional array, using two for loops.
for (String[] a : names) { for (String s : a) { System.out.println(s); } }
Is there a new elegant way to loop and print a 2D array using Java 8 features (Lambdas, method reference, threads, ...)?
What I have tried so far is the following:
Arrays.asList(names).stream().forEach(System.out::println);
Conclusion:
[Ljava.lang.String;@6ce253f1 [Ljava.lang.String;@53d8d10a [Ljava.lang.String;@e9e54c2
source share