集合體系概述
Collection常用方法
補充:addAll()
Collection的遍歷方式
迭代器
增強for(空集合可以,null不可以)
lambda
集合對象存儲對象原理
遍歷方式的區別
List集合
特點、特有方法
遍歷方式
(同上)
ArrayList底層原理
LinkedList底層原理
手寫鏈表
/*** 手寫鏈表*/
public class MyLinkedList<E> {private int size = 0;Node<E> first;public static class Node<E> {E item;Node<E> next;public Node(E item, Node<E> next){this.item = item;this.next = next;}}public boolean add(E e) {Node<E> newNode = new Node<>(e, null);if(first == null) {first = newNode;} else {Node<E> temp = first;while(temp.next != null) {temp = temp.next;}temp.next = newNode;}size++;return true;}@Overridepublic String toString() {StringJoiner s = new StringJoiner(",", "[", "]");Node<E> temp = first;while(temp != null) {s.add(temp.item + "");temp = temp.next;}return s.toString();}public int size(){return size;}}class Test {public static void main(String[] args) {MyLinkedList<String> list = new MyLinkedList<>();list.add("1號客人");list.add("2號客人");list.add("3號客人");list.add("4號客人");System.out.println(list);}
}
Set集合
特點
HashSet底層原理
了接下數據結構(樹)
查詢性能提高:排序
去重機制
LinkedHashSet底層原理-有序
TreeSet底層原理-排序
*優先選擇
Map集合
概述
常用方法
遍歷方法
HashMap-原理