《Java程序设计Java程序设计 (16).pdf》由会员分享,可在线阅读,更多相关《Java程序设计Java程序设计 (16).pdf(28页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、61.JavaCollection2.ListArrayListLinkedListIterator3.SetHashSet4.MapHashMap5.6.1.Java(Java Collection Framework)1.-Javajava.utilListArrayList,LinkedListJava1.-JDKCollectionListSetMapArrayListLinkedListHashSetTreeSetHashMapTreeMap2.List2.1 Collection2.2 List2.3 ArrayList2.4 LinkedList2.5 IteratorColle
2、ctionListSetMapArrayListLinkedListHashSetTreeSetHashMapTreeMap2.Listboolean add(Object o)oboolean addAll(Collection c)cvoid clear()boolean remove(Object o)oboolean removeAll(Collection c)cboolean isEmpty()boolean contains(Object o)oboolean containsAll(Collection c)cIterator iterator()Iteratorint siz
3、e()Collection2.ListListListListListvoid add(int index,Object o)oListindexboolean addAll(int index,Collection c)cListindexObject get(int index)indexObject remove(int index)indexObject set(int index,Object o)indexoint indexOf(Object o)oListint lastIndexOf(Object o)oListList subList(int from,int to)fro
4、m()to()2.ListArrayListArrayListadd()get()ArrayListjava.utilArrayListArrayList2.ListLinkedListListLinkedListLinkedListLinkedList121233122.ListLinkedListLinkedListLinkedListvoid add(int index,Object o)indexovoid addFirst(Object o)ovoid addLast(Object o)oObject getFirst()Object getLast()Object removeFi
5、rst()Object removeLast()ArrayListLinkedListArrayListLinkedList()JDKIteratorCollectionIteratorIteratorArrayListObject2.ListIterator12调用next()的返回值调用next()之前第1次调用next()第2次调用next()hasNext()返回false迭代器终止.3.Set3.1 HashSet3.2 TreeSetCollectionListSetMapArrayListLinkedListHashSetTreeSetHashMapTreeMap3.SetSet
6、SetHashSetTreeSetHashSetTreeSet3.SetHashSetHashSet(HashSetDemo01.java)HashSetadd()HashSethashCode()hashhash该位置是否有对象存在equal()判断是否相等是是否否HashSetObjecthashCode()equals()StudentHashSet(HashSetDemo02.java)3.SetTreeSetTreeSetSortedSetSortedSetComparator comparator()Object first()Object last()SortedSet head
7、Set(Object o)o()SortedSet subSet(Object from,Object to)from()to()SortedSet tailSet(Object o)o()TreeSet(TreeSetDemo01.java)4.Map4.1 Map4.2 HashMap4.3 TreeMapCollectionListSetMapArrayListLinkedListHashSetTreeSetHashMapTreeMap4.MapMapMap staff=new HashMap();staff.put(20150001,new Employee();staff.put(2
8、0150002,new Employee();Employee e=staff.get(20150001);e=staff.remove(20150001);system.out.println(staff.size();4.MapMapvoid put(Object key,Object value)Object get(Object key)nullboolean containsKey(Object key)keytrueboolean containsValue(Object value)valuetrueSet keySet()SetCollection values()Collec
9、tionSetMap.Entry entrySet()Set4.MapHashMapHashMapput()get()HashMapDemo01.javaMap(HashMapDemo02.java)(HashMapDemo03.java)4.Map-TreeMapTreeMapSortedMapTreeMapkey(TreeMapDemo01.java)5.Object5.ObjectGenericDemo01.java5.GenericDemo01.javaArrayListStringEclipseArrayList list=new ArrayList();6.()JavaEEStudentSchoolTestDemo.java6.StudentCourseTestDemo.javaCollection MapListSetMap