Java two dimensional array

two dimensional array 拥有两个不同的内存地址

int[][] a = new int[3][];
a[0] = new int[2];
a[1] = new int[3];
a[2] = new int[4];

a[1][2] = 5;

Example:
package twoDimensionalArrays;

public class InitialValueRagged {

	public static void main(String[] args) {
		int a[][] = { {2, 3, 5}, {7}, {8, 9, 10, 23, 55}};//直接创建two dimensional array的方法
		
		for (int row = 0;  row < a.length; row++) {
			for (int col = 0; col < a[row].length; col++) {
				System.out.print(a[row][col] + "  ");
			}
			System.out.println();
		}
		

	}

}
输出为:
2  3  5  
7  
8  9  10  23  55  


你可能感兴趣的:(Java)