Java learning notes (6) — collection collection


Collection collection

java.util.Collection Interface
A collection is a container that can store a variety of data
The array length is fixed, and the collection length is variable,
Arrays can store basic types or objects. Collections can only storeobject, types can be inconsistent

Collection framework

Learning top
Use bottom layer

Collection interface

It’s all definedSingle column setThe Communist approach, allSingle column setWe can use common methods
There is no indexed method

Java learning notes (6) -- collection collection

List interface

1. Ordered collection (store and retrieve elements in the same order)
2. Allow to store duplicate elements
3. With index, you can use ordinary for loop traversal

Vector set
ArrayList collection
LinkedList collection

Set interface

1. Duplicate elements are not allowed to be stored
2. Without index, we can’t use the ordinary for loop to traverse

TreeSet set

The order of storage and retrieval may be inconsistent

HashSet collection

The order of storage and retrieval may be inconsistent

Linkedhashset collection (a subclass of HashSet)

Ordered set

Common methods of collection

boolean add(E e)

void clear()

boolean remove(E e)

boolean contains(E e)
Does the current collection contain the given object

boolean isEmpty()

int size()

Object[] toArray()