How are arrays implemented in java?

前端 未结 4 1445
一向
一向 2020-12-03 05:14

Arrays are implemented as objects in java right? If so, where could I look at the source code for the array class. I am wondering if the length variable in arrays is defined

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-03 05:43

    For every Array we declare, corresponding classes are there in Java but it's not available to us.You can see the classes by using getClass().getName()

        int[] arr=new int[10];
        System.out.println(arr.getClass().getName());
    

    Output : [I

    where "[" represents one dimension array and "I" represents Integer. Similarly, we can have

        [F for one-dimensional float arrays
        [Z for one-dimensional boolean arrays
        [J for one-dimensional long arrays
        [[I for two-dimensional int arrays
    

    and so on.

提交回复
热议问题