集册 Java实例教程 知道数组的类别

知道数组的类别

欢马劈雪     最近更新时间:2020-01-02 10:19:05

507
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
知道数组的类别

public class Main {

  public static void main (String[] args){

    int[] iArr = new int[2];/** 来 自 N o w J a v a . c o m**/

    int[][] iiArr = new int[2][2];

    int[][][] iiiArr = new int[2][2][2];

    

    String[] sArr  = {"A", "B"} ;

    String[][] ssArr = {{"AA"}, {"BB"}} ;

    String[][][] sssArr = {} ; // A 3D empty array of string


    // Print the class name for all arrays  

    System.out.println("int[]:" + getClassName(iArr));

    System.out.println("int[][]:" + getClassName(iiArr));/**from n o w  j a v a  . c o m**/

    System.out.println("int[][][]:" + getClassName(iiiArr));

    System.out.println("String[]:" + getClassName(sArr));

    System.out.println("String[][]:" + getClassName(ssArr));

    System.out.println("String[][][]:" + getClassName(sssArr));

  }


  // Any java object can be passed to getClassName() method.

  // Since every array is an object, we can also pass an array to this method.

  public 
展开阅读全文