0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

要素数が異なる2次元配列の取り出し方(備忘録)

Posted at

要素数が異なる2次元配列の取り出し方

public static void main(String[] args) {
	// 配列用意
	int[][] array = new int[][] { { 1, 2 }, { 2, 3, 4 } };

	// 2次元配列の要素数
	System.out.println("2次元配列の要素数: " + array.length);
	// 2次元配列の[0]に入っている配列の要素数
	System.out.println("2次元配列の[0]に入っている配列の要素数: " + array[0].length);
	// 2次元配列の[1]に入っている配列の要素数
	System.out.println("22次元配列の[1]に入っている配列の要素数: " + array[1].length);

	// 配列の中身全てのとり出す
	for (int i = 0; i < array.length; i++) {
		for (int j = 0; j < array[i].length; j++) {
			System.out.println("array[" + i + "][" + j + "] = " + array[i][j]);
		}
	}
}

コンソール結果

2次元配列の要素数: 2
2次元配列の[0]に入っている配列の要素数: 2
22次元配列の[1]に入っている配列の要素数: 3
array[0][0] = 1
array[0][1] = 2
array[1][0] = 2
array[1][1] = 3
array[1][2] = 4
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?