

下面是我自己畫的,關系畫得沒上面好,但我自己看著清楚些

還有一張下載來的:

|
有序否
|
允許元素重復否
|
Collection
|
否
|
是
|
List
|
是
|
是
|
Set
|
AbstractSet
|
否
|
否
|
HashSet
|
TreeSet
|
是(用二叉樹排序)
|
Map
|
AbstractMap
|
否
|
使用key-value來映射和存儲數據,Key必須惟一,value可以重復
|
HashMap
|
TreeMap
|
是(用二叉樹排序)
|
幾個面試常見問題:
1.Q:ArrayList和Vector有什么區別?HashMap和HashTable有什么區別?
A:Vector和HashTable是線程同步的(synchronized)。性能上,ArrayList和HashMap分別比Vector和Hashtable要好。
2.Q:大致講解java集合的體系結構
A:List、Set、Map是這個集合體系中最主要的三個接口。
其中List和Set繼承自Collection接口。
Set不允許元素重復。HashSet和TreeSet是兩個主要的實現類。
List有序且允許元素重復。ArrayList、LinkedList和Vector是三個主要的實現類。
Map也屬于集合系統,但和Collection接口不同。Map是key對value的映射集合,其中key列就是一個集合。key不能重復,但是value可以重復。HashMap、TreeMap和Hashtable是三個主要的實現類。
SortedSet和SortedMap接口對元素按指定規則排序,SortedMap是對key列進行排序。
3.Q:Comparable和Comparator區別
A:調用java.util.Collections.sort(List list)方法來進行排序的時候,List內的Object都必須實現了Comparable接口。
java.util.Collections.sort(List list,Comparator c),可以臨時聲明一個Comparator 來實現排序。
Collections.sort(imageList, new Comparator() {
public int compare(Object a, Object b) {
int orderA = Integer.parseInt( ( (Image) a).getSequence());
int orderB = Integer.parseInt( ( (Image) b).getSequence());
return orderA - orderB;
}
});
如果需要改變排列順序
改成return orderb - orderA 即可。
4.Q:簡述equals()和hashCode()
A:...不知道。下回分解
public interface
Collection
extends Iterable
public interface
List
extends Collection
public abstract class
AbstractList
extends AbstractCollection
implements List
public class
Vector
extends AbstractList
implements List,
RandomAccess,
java.lang.Cloneable,
java.io.Serializable
基于Array
是“sychronized”的
public class
ArrayList
extends AbstractList
implements List,
RandomAccess,
Cloneable,
java.io.Serializable
基于Array
ArrayList是非同步的。所以在性能上要比Vector優越一些
public class
LinkedList
extends AbstractSequentialList
implements List,
Queue,
Cloneable,
java.io.Serializable
不基于Array
基于Array的List(Vector,ArrayList)適合查詢,而LinkedList(鏈表)適合添加,刪除操作
List基本上都是以Array為基礎。但是Set則是在HashMap的基礎上來實現的,這個就是Set和List的根本區別
public abstract class AbstractSet
extends AbstractCollection
implements Set
public class HashSet
extends AbstractSet
implements Set, Cloneable, java.io.Serializable
HashSet的存儲方式是把HashMap中的Key作為Set的對應存儲項
public class LinkedHashSet
extends HashSet
implements Set, Cloneable, java.io.Serializable
public class TreeSet
extends AbstractSet
implements SortedSet, Cloneable, java.io.Serializable
它是通過SortedMap來實現的
public interface Map<K,V>
public abstract class AbstractMap<K,V>
implements Map<K,V>
public class HashMap<K,V>
extends AbstractMap<K,V>
implements Map<K,V>, Cloneable, Serializable
public class TreeMap<K,V>
extends AbstractMap<K,V>
implements SortedMap<K,V>, Cloneable, java.io.Serializable
HashMap通過hashcode對其內容進行快速查找,而TreeMap中所有的元素都保持著某種固定的順序,如果你需要得到一個有序的結果你就應該使用TreeMap(HashMap中元素的排列順序是不固定的)
更詳細的可以看:
http://www.frontfree.net/view/article_695.html
http://blog.csdn.net/happyzhm5/archive/2007/03/17/1532101.aspx
http://blog.csdn.net/Java_apprentice/archive/2007/07/20/1700351.aspx
posted on 2007-11-12 10:06
EvanLiu 閱讀(116941)
評論(14) 編輯 收藏 所屬分類:
Java基礎