Home  >  Article  >  Java  >  Detailed explanation of the relationship between Java array types

Detailed explanation of the relationship between Java array types

WBOY
WBOYforward
2023-05-08 12:49:07898browse

1. Relationship description

(1) Array

The array is a reference data type, and the array reference variable is just a reference (similar to the pointer in C ), array elements and array variables are in memory

(2) Object array

Since classes and arrays are both reference data types, the object array o2 in the program actually stores Reference array of class Obj.

(3) Multidimensional array

A multidimensional array is an extension of an array. It is essentially a one-dimensional array, but the array elements are also references, and the references saved in the array elements point to the one-dimensional array.

2. Example

public class Obj{
    int a;
}
public class Test{
    public static void main(String[] args){
        int array[]    = int[]{2,3,4,5,6,7,8,9};
        Obj o1         = new Obj();
        Obj o2[]       = new Obj[10];
        int array2[][] = new int[10][];
    }
}

What collection classes are there in Java?

Collections in Java are mainly divided into four categories:

1 , List list: ordered, repeatable;

2, Queue queue: ordered, repeatable;

3, Set collection: non-repeatable;

4. Map mapping: unordered, unique keys, but not unique values.

The above is the detailed content of Detailed explanation of the relationship between Java array types. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete