Home >Java >JavaBase >what is collection java

what is collection java

angryTom
angryTomOriginal
2019-11-11 09:17:013256browse

what is collection java

What is collection java

1. The origin of collection

Usually, our Java program needs to know how many objects are created when the program is running. But if the program is not running, during the program development stage, we have no idea how many objects are needed, or even their exact type. In order to meet these general programming needs, we require that any number of objects can be created at any time and anywhere. What are these objects used to accommodate? We thought of arrays first, but! Arrays can only store data of the same type, and their length is fixed, so what should we do? The collection came into being. ( Recommended tutorial: java tutorial )

2. What is a collection?

The Java collection class is stored in the java.util package, is a container used to store objects.

Note:

1. Collections can only store objects. For example, if you store an int type data 66 into a collection, it is actually converted into an Integer class and then stored automatically. Each basic data type in Java has a corresponding reference type.

2. Collections store references to objects, not the objects themselves. So we call the objects in the collection the references to the objects in the collection. The object itself is still placed in the heap memory.

3. Collections can store different types of data types, with no limit on the number.

3. Collections in Java are mainly divided into four categories:

● List list, ordered, repeatable

● Queue queue, with Ordered, repeatable

● Set collection, non-repeatable

● Map mapping, unordered, unique keys, non-unique values ​​Each collection type contains multiple specific implementation classes

The above is the detailed content of what is collection java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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