



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An outline and explanation of java collections, including major types (sets, bags, lists, maps), interfaces (collection, set, list, map), implementation classes (hashset, linkedhashset, treeset, arraylist, linkedlist, hashmap, identityhashmap, linkedhashmap, treemap, hashtable), iterators, input/output classes, and ordering. It covers the methods and descriptions of each interface and implementation class, as well as examples and use cases.
Typology: Study notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Method Description add(o) Add a new element addAll(c) Add all elements of c remove(o) Remove an element removeAll(c) Remove all elements found in c retainAll(c) Retain only elements found in c clear() Remove all elements contains(o) Membership testing containsAll(c) Membership testing isEmpty() Whether it is empty size() The number of elements iterator() Return an iterator
Method Description add(o) Add an element if not already present addAll(c) Add each elements of c if not present
Method Description add(i, o) Insert o at the i-th position add(o) Append o at the end addAll(i, c) Insert all elements of c starting at the i-th position addAll(c) Append all elements of c at the end remove(i) Remove i-th element remove(o) Remove the first occurrence of o set(i, o) Replace i-th element with o get(i) Return i-th element indexOf(o) Return the index of the first occurrence of o lastIndexOf(o) Return the index of the last occurrence of o listIteratpr() Return a list iterator listIterator(i) Return a list iterator for the sublist starting from i subList(i, j) Retrun a sublist between index iand j
Method Description put(k,v) Associate v with k remove(k) Remove the mapping for k clear() Remove all mappings get(k) The value associated with k containsKey(k) Whether contains a mapping for k containsValue(v) Whether contains a mapping to v size() The number of pairs isEmpty() Whether it is empty ….
Method Description entrySet() Set of key-value pairs keySet() Set of keys values() The collection of values k k k . . . kn v v v . . . vn keySet() values() entrySet()
Class Interface Description HashSet Set Hash table LinkedHashSet Set Hash table & DLL TreeSet SortedSet Balanced binary tree
Class Interface Description ArrayList List Resizable array LinkedList List Doubly linked list Vector List Legacy of JDK 1.
Class Interface Description HashMap Map Hash table IdentityHashMap Map Hash table with identity comparison LinkedHashMap Map Hash table and DLL TreeMap SortedMap Balanced binary tree Hashtable Map Legacy of JDK 1.
SortedSet s1 = new SortedSet(); SortedSet s2 = new SortedSet(new PersonComparator()); SortedMap m1 = new SortedMap(); SortedMap m2 = new SortedMap(new PersonComparator());
Method Description comparator() Return the comparator first() Return the first (lowest) element last() Return the last (highest) element headSet(o) Return elements less than o tailSet(o) Return elements greater than or equal to o subSet(o1,o2) Return elements between o1 and o
Method Description comparator() Return the comparator firstKey() Return the first (lowest) key lastKey() Return the last (highest) key headMap(k) Return maplets less than k tailMap(k) Return maplets greater than or equal to k subMap(k1,k2) Return maplets between k1 and k
String fileName = …; BufferedReader reader = new BufferedReader( new InputStreamReader(new FileInputStream(fileName))); String line; while ((line = reader.readLine()) != null) { // do something with line … }