1.面試題:Collection和Collections的區別
Collections類:是一個類,封裝了Set,List,Map的操作的工具方法.
獲取空集對象(沒有元素的集合,注意集合不爲null):即空集不是對象爲null.而是對象裏面的數據爲空
HashSet/ArrayList/HashMap都是線程不安全的,在多線程環境下不安全.
在Collections類中有獲取線程安全的集合方法:
List list = Collections.synchronizedList(new ArrayList());
Set set = Collections.synchronizedSet(new HashSet());
Map map = Collections.synchronizedMap(new HashMap());
synchronized(list或者set或者map) {
//TODO
}