Create Print2DArray.java

This commit is contained in:
Neetika23 2023-11-21 16:31:48 +05:30 committed by GitHub
parent 4e4fa700ae
commit b8c875adbd
1 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,23 @@
package com.baeldung.print2DArrays;
import java.util.*;
public class Print2DArray{
public static void print2DNested(int[][] myArray){
for (int i = 0; i < myArray.length; i++) {
for (int j = 0; j < myArray[i].length; j++) {
System.out.print(myArray[i][j] + " ");
}
System.out.println();
}
}
public static void print2DStream(int[][] myArray){
Arrays.stream(myArray).flatMapToInt(Arrays::stream).forEach(num -> System.out.print(num + " "));
}
public static void print2DDeepToString(int[][] myArray){
System.out.println(Arrays.deepToString(myArray));
}
}