java15章总结
泛型聲明:
class 類名<泛型列表(任何一個(gè)標(biāo)識(shí)符都可以)>
泛型列表可以作為類的成員變量的類型,方法的類型以及局部變量的類型
泛型類聲明對(duì)象后面帶<>:
Cone<Circle> cone;
cone = new Cone<Circle>();
鏈表:
LinkedList<E>泛型類創(chuàng)建的對(duì)象以鏈表的結(jié)構(gòu)存儲(chǔ)數(shù)據(jù),E要指定具體類型。
LinkedList<String> list = new LinkedList<String>();
用add(E obj)的方法依次加結(jié)點(diǎn)。
list.add("How");
方法:
LinkedList<E>是實(shí)現(xiàn)了接口List<E>的泛型類,List<E>實(shí)現(xiàn)接口Collection<E>的子接口。
遍歷:
鏈表對(duì)象用iterator()方法獲得一個(gè)Iterator對(duì)象
Iterator<String> iter = list.iterator();
while(iter.hasNext())遍歷
ArryList類是順序結(jié)構(gòu)的動(dòng)態(tài)數(shù)組,與LinkedList方法很多類似。
排序查找
Collections 類提供的方法:
sort(List<E> list)升序
binarySearch(List<T> list,T key,CompareTo<T> c)使用折半法找是否有key相等的元素,如果有返回他的位置,從0開始。
要實(shí)現(xiàn)Comparable接口中的方法intcompareTo(Object b).
洗牌旋轉(zhuǎn)
void shuffle(List<E> list) list的數(shù)據(jù)重新隨機(jī)排序
rotate(List<E> list,int distance)選擇數(shù)據(jù)?
reverse(List<E> list)翻轉(zhuǎn)
棧
Stack<E> 泛型類建立一個(gè)堆棧對(duì)象
push<E item>?
pop();
boolean empty();
peek();
search(Object data);
散列映射
HashMap<K,V>實(shí)現(xiàn)接口Map<K,V>
HashMap<String,Student> h =?HashMap<String,Student>();
h就可以儲(chǔ)存鍵/值對(duì)數(shù)據(jù),鍵必須是String對(duì)象,對(duì)值必須是Student對(duì)象
V put<K key,V value>存入
樹集
TreeSet<E> Set<E>
樹映射
TreeMap<K,V>? Map<K,V>
?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
總結(jié)
- 上一篇: 潜藏在人体体内的12种毒素
- 下一篇: 换位思考的最高境界是换待遇,所以,换位思