Home > Java > javaTutorial > body text

Detailed explanation of the relationship between Java array types

WBOY
Release: 2023-05-08 12:49:07
forward
914 people have browsed it

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][];
    }
}
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template