【定义】
表示object的集合
generic class:可以用于多种object,
抽象类的具体实现:
【ArrayList】
动态添加,只能加Non-primitive type,要初始化长度。
【compare】记忆方法:BT1 用this,T02 用object
comparable:比较natural order,comparator的compare可以比较2个物体,定义不同的order
public void sortAndPrint() {
Collections.sort(books); //natural order
printCollection();
Collections.sort(books, new AuthorComparer());
printCollection();
Collections.sort(books, new YearComparer());
printCollection();
}
//inner classes
public class AuthorComparer implements Comparator <Book> {
public int compare(Book b1, Book b2) {
return b1.author.compareTo(b2.author);
}}
public class YearComparer implements Comparator <Book> {
public int compare(Book b1, Book b2) {
return (b1.year - b2.year);
}
}}
【iterator】
【Arraylist】
只存了引用,元素的位置随意。
Java offers only doubly linked list data structure. If you needed a circular or a singly linked list in your program,
Create my own custom-made linked list。只有双向链表。