Java collections are divided into three categories:
- List : Stores an array that can be expanded automatically
- Set : Stores an array with no duplicate elements
- Map: an associative array that stores the mapping relationship
List is divided into: Arraylist and Linkedlist
-> Arraylist is an auto-expandable, variable-length, dynamic array data structure, fast to access elements, slow to insert and delete
创建集合的对象:
ArrayList < Student> list=new ArrayList< Student>();
遍历: 迭代器
Iterator< Student> it=list.iterator();//迭代器输出
while(it.hasNext())
{
Student s=(Student) it.next(); //转换为Student类
System.out.printf("%s %d\n",s.name,s.score);
}
Sorting (->My Blog): There are two methods (implementing Comparator or implementing the compareTo method in the Comparable interface)
https://blog.csdn.net/qq_37486501/article/details/79999552
->Linkedlist is a linked list data structure, which is slow to access elements and fast to insert and delete
(the method is the same as ArrayList)
Set is divided into: Hashset and Treeset
->Hashset is not sorted, and the access speed is fast
(the method is the same as ArrayList)
->Treeset is sorted, you can achieve custom sorting by implementing the Comparable interface
(the method is the same as ArrayList)
Map is divided into: Hashmap and Treemap
->Hashmap is not sorted
创建集合的对象:(自己定义key和value的类型)
HashMap<String,Integer> map=new HashMap<String,Integer>();
Sort (-> my blog): https://blog.csdn.net/qq_37486501/article/details/80141611
-> Treemap is sorted