Disclaimer: The materials used in this column are written by VIP students of Kaige Academy. Students have the right to remain anonymous and have the right to final interpretation of the article. Kaige Academy aims to promote VIP students to learn from each other based on public notes.
Collection family:
Introduction: It is composed of interfaces. Its highest interface is Collection, followed by List and Set, and Map. The purpose of applying for these interfaces is to think about standards and unity. As shown in the figure below, it contains branches of the family.
Collection family methods:
as shown below: Collection methods in it
Set: no method
List:
as shown below: it is a method in List
ArrayList:
as shown below: ArrayList has an int parameter passed in it, passing in 100 means the initialization length, which is the initial size of the array
Vector:
The following are the methods of Vector
Stack collection:
push into the stack, pop out of the stack, Peek who is currently going to pop out of the stack, an exception will be thrown if there is no back, and popping out of the stack is equivalent to deleting
LinkedList:
addFirst is added forward, addLast is added backward, getFirst gets the former, getLast gets the latter, removeFirst deletes the former, removeLst deletes the latter
HashSet:
If you add many s1s, it is still only one, because it cannot add duplicate values
TreeSet :
It is a sorted set. It is to be sorted when your data is added. If you add this Dog to it, it will report an error. It requires this class to be implemented in this interface before it can be sorted.
You have to implement this interface. If you are greater than it, return 1, if it is equal to it, return 0, and if it is less than it, return -1
Then sort by dog's age