Consider this two dimentional array
String[][] names = { {"Sam", "Smith"},
{"Robert", "Delgro"},
{"James", "Gosling"},
};
Using the classic way, if we want to access each element of a two dimensional array, then we need to iterate through 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 2D array using Java 8 features (Lambdas,method reference,Streams,...)?
What I have tried so far is this:
Arrays.asList(names).stream().forEach(System.out::println);
Output:
[Ljava.lang.String;@6ce253f1
[Ljava.lang.String;@53d8d10a
[Ljava.lang.String;@e9e54c2