ArrayList and HashSet classes under Java collections

Collection concept: 1. In order to save an indeterminate amount of data;
                2. Save data with a mapping relationship (also known as an associative array).
Java provides collection classes, which are mainly responsible for saving and holding other data, so collection classes are also called container classes. All collection classes are located under java.util
Java's collection class is mainly derived from two interfaces: Collection and Map;
Collection and Map are the root interfaces of the Java Collections Framework.

Only ArrayList and HashSet under List and Set are described here;

The following is an example of ArrayList, only common examples are listed
Instance of HashSet()

ArrayList is a way of data storage; ArrayList is implemented through variable-sized arrays, allowing all elements including null;

The storage order and addition order in ArrayList are the same. and repeatable

HashSet storage will first compare the HashCode value, if it is the same, it will not be stored again, so the same element will not be stored

Hashset is a collection of objects that use a hash algorithm to access objects

The unordered storage order of HashSet storage is inconsistent with the addition order,


add() adds the specified element to the end of the article;

addAll() adds the specified set to the end of the list;
clear() clears all elements of the column;

contains(Object o)

Returns true if this list contains the specified element

get(int index)

Returns the element at the specified position in this list.
remove(int index)
removes the element at the specified position in this list

size()
Returns the number of elements in this list

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324642698&siteId=291194637