Java learning Note 1 -- set and java note set
1. What is a set?
A set is a set of objects, just as an array is a set of numbers. A collection is a container that can store objects (different types of objects can be used ).
Ii. Advantages of a set (Why use a set)
Of course, in java, Arrays can be used to store a group of identical objects. However, there are two disadvantages for storing objects in arrays (set advantages ):
Iii. collection implementation
Java integration is implemented by two interfaces:CollectionAndMap, Collection has two sub-interfaces:SetAndList.
Collection Interface
| ------- List Interface
| ------- ArrayList class (similar to an array), sort list class (similar to a linked list), and Vector class (thread-safe, but old, not commonly used)
| ------- Set Interface
| ------- HashSet, LinkedHashSet, TreeSet
Map Interface
| ------- HashMap, LinkedHashMap, TreeMap, Hashtable
Features of each interface:
Set: The elements are unordered and cannot be repeated. SortedSet is a Set that sorts elements in ascending order.
List: The elements are ordered and can be repeated. Provides an index-based access method. It can be viewed as a "dynamic array ",
Map: Key-value pairs with ing relationships "key-value. A key corresponds to a value, which is used to find the value. Therefore, the key cannot be repeated, and the value can be repeated.
Inheritance tree for the Collection interface: