0、
集合最重要的應該是前兩項,相關資料結構的用途和排序方式都很重要,
例題要另外自己去找來看。
1、
arraylist、hashmap、linkedlistlist、hashset的不同處?
hashmap是雜湊,用於身份證之類的資料搜尋
hashset是雜湊集合,用於不重覆資料或是排除重覆資料的程式
arraylist是陣列串列,一般速度最快,適用於排序法
linkedlist是鏈結串列,用於常插入更新的資料
2、
還是不大了解hashset、arraylist、hashmap之類的東西,因此嘗試用一句話進行整理。
如果要排序的話,可以看下面的例子:
List底下是ArrayList和LinkList
如果要排序的話,可以看下面的例子:
List底下是ArrayList和LinkList
Collections用於List底下的資料,不接受Set型別
EX:Collections.sort(s);
Set底下有HashSet和(介面不能new的)SoretedSet、(可以new的)TreeSet
只有TreeSet()可以拿來排序Set資料
EX:Set set = new TreeSet();
Map型態有SortedMap、TreeMap、HashMap
hashmap是雜湊,用於身份證之類的資料搜尋,HashMap可以利用key值迅速取得value
SortedMap比較少人使用,可以排序用
EX:Collections.sort(s);
Set底下有HashSet和(介面不能new的)SoretedSet、(可以new的)TreeSet
只有TreeSet()可以拿來排序Set資料
EX:Set set = new TreeSet();
Map型態有SortedMap、TreeMap、HashMap
hashmap是雜湊,用於身份證之類的資料搜尋,HashMap可以利用key值迅速取得value
SortedMap比較少人使用,可以排序用
--
例題:
34. HashMap props=new HashMap();
35. props.put("key45", "some value");
36. props.put("key12", "some other value");
37. props.put("key39", "yet another value");
38. Set s = props.keySet();
39. // insert code here
What, inserted at line 39, will sort the keys in the props HashMap?
A. Arrays.sort(s);
B. s = new TreeSet(s);
C. Collections.sort(s);
D. s =new SortedSet(s);
--
A只能用於陣列資料
B用於Set類別的資料,不接受List
C用於List底下的資料,不接受Set型別
D介面不能new
--
答案是B
全站熱搜