1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| System.arrayCopy(oldArray, 0, newArray, 0, oldArray.length);
add(Object o) add(int i, Object o) clear() Contains(Object o) get(int i) indexOf(Object o) remove(Object o) remove(int i) toArray()
List list = new ArrayList(); Iterator it = list.iterator(); while (it.hasNext()) Object o = it.next();
LinkedList list = new LinkedList(); ListIterator it = list.listIterator(); while (it.hasNext()) Object o = it.next();
HashMap<String, String> hm = new HashMap<String, String>(); hm.get(key); hm.put("No1", "Hexinyu"); hm.put("No2", "Sean");
Iterator<String> it = hm.values().iterator(); while (it.hasNext()) { String myKey = it.next(); String myValue = hm.get(myKey); }
for (String key : hm.keySet()) { String myKey = key; String myValue = hm.get(myKey); }
Preferences prefs = Preferences.userNodeForPackage(ArrayDemo.class); String text = prefs.get("textFontName", "lucida-bright"); String display = prefs.get("displayFontName", "lucida-balckletter"); System.out.println(text); System.out.println(display);
prefs.put("textFontName", "new-bright"); prefs.put("displayFontName", "new-balckletter");
InputStream in = MediationServer.class.getClassLoader().getResourceAsStream("msconfig.properties"); Properties prop = new Properties(); prop.load(in); in.close(); prop.setProperty(key, value); prop.getProperty(key);
1. 数组: Arrays.sort(strings); 2. List: Collections.sort(list); 3. 自定义类: class SubComp implements Comparator 然后使用 Arrays.sort(strings, new SubComp())
1. java.lang.Comparable: 提供对象的自然排序, 内置于类中 int compareTo(Object o); boolean equals(Object o2); 2. java.util.Comparator: 提供特定的比较方法 int compare(Object o1, Object o2)
TreeMap sorted = new TreeMap(unsortedHashMap);
Hashset hs - new HashSet();
binarySearch(): 快速查询 - Arrays, Collections contains(): 线型搜索 - ArrayList, HashSet, Hashtable, linkedList, Properties, Vector containsKey(): 检查集合对象是否包含给定 - HashMap, Hashtable, Properties, TreeMap containsValue(): 主键 ( 或给定值) - HashMap, Hashtable, Properties, TreeMap indexOf(): 若找到给定对象, 返回其位置 - ArrayList, linkedList, List, Stack, Vector search(): 线型搜素 - Stack
toArray();
Collection: Set - HashSet, TreeSet Collection: List - ArrayList, Vector, LinkedList Map: HashMap, HashTable, TreeMap
|