「Java」多次元配列の長さを取得するサンプル

書式
配列変数名.length

Javaコード

package com.example;

public class NijikenArr {

      public static void main(String[] args) {

            int aa[][] ={
                        {18,12,21},
                        {21,22,23}
                        };
            String [][] data = {
                        {"AGE","18","年齢"},
                        {"ADDRESS","tokyo","東京"},
                        {"USERNAME","yamada","山田"}
            };
            System.out.println("実行結果:");
            System.out.println("長さ1: "+ aa.length + "\n長さ2: "+ data.length);
      }
}

実行結果:
長さ1: 2
長さ2: 3

Java

Posted by arkgame