目標(biāo):構(gòu)建一個List
先看List是什么闺属,jdk里的定義如下:
An ordered collection (also known as a sequence) The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list), and search for elements in the list.
簡單的說就是一個有序的集合:
1.用戶可以對其中每個元素的插入位置進(jìn)行精確地控制蛛株。
2.用戶可以根據(jù)元素的整數(shù)索引(在列表中的位置)訪問元素,并搜索列表中的元素喂急。
歸納為:設(shè)計一個數(shù)據(jù)容器,支持隨機(jī)或者順序增刪改查笛求。
二話不說廊移,先上代碼:
public class MyList{
public boolean add(Object e) {
return false;
}
public boolean remove(Object o) {
return false;
}
public Object get(int index) {
return null;
}
public Object set(int index, Object element) {
return null;
}
public void add(int index, Object element) {
}
public Object remove(int index) {
return null;
}
public int indexOf(Object o) {
return 0;
}
}
具體實現(xiàn),請看下回分解