0% found this document useful (0 votes)
21 views

SCJPTps Collections

The document summarizes key aspects of Java's Collection Framework. It discusses the Collection interface and common methods like add(), remove(), contains(). It then describes common List, Set, Queue, and Map implementations like ArrayList, LinkedList, HashSet, HashMap and their characteristics. It also covers usage of iterators, comparators, and generics with Collections.

Uploaded by

Pankaj Thakur
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

SCJPTps Collections

The document summarizes key aspects of Java's Collection Framework. It discusses the Collection interface and common methods like add(), remove(), contains(). It then describes common List, Set, Queue, and Map implementations like ArrayList, LinkedList, HashSet, HashMap and their characteristics. It also covers usage of iterators, comparators, and generics with Collections.

Uploaded by

Pankaj Thakur
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Collection Interface Collection super most interface of Collection Framework. Add(), remove(), contains() and their bulk operations.

. Iterator(). List index based methods. add(int, Object), set(int, Object). Iterator(), listIterator() Set unique(equals() ). No new methods. Queue priority Collection Classes List Implementation ArrayList - Implements List LinkedList implements List, Queue, Deque interace Vector legacy. All methods synchronized. Cant add null. Implements List Set Implementation HashSet unique(equals() ), no ordering LinkedHashSet unique(equals() ), insertion order TreeSet unique(equals() ), sorted order (Comparable/Comparator), implements NavigableSet Queue implementation PriorityQueue - sorted order (Comparable/Comparator), will show order only in methods and not in iterator() or System.out.println() Map Interface Map Keys unique, key-value pair, put(key,value), get(key), putting duplicate key will replace old value, multiple null values allowed Map m = new HashMap (); Set<Map.Entry> entrySet() Collection values() Set keySet() Map<String, Integer> m = new HashMap<String, Integer>(); Set<Map.Entry<String, Integer> > entrySet()

Collection<Integer> values() Set<String> keySet() Map Implementation Classes HashMap Keys unique, 1 null key allowed, no ordering LinkedHashMap - Keys unique, 1 null key allowed, insertion order TreeMap - Keys unique, adding null key will compile but throw NullPointerException at run time Hashtable legacy class, methods synchronized, Keys unique, no null key or value allowed, no ordering Sorting (Comparable / Comparator) NavigableSet interface (TreeSet class) Constructors: TreeSet() TreeSet(Comparator) // Comparable interface // Provide Comparator object

NavigableMap interface (TreeMap class) Constructors: TreeMap() TreeMap(Comparator) // Comparable interface // Provide Comparator object

Comparable - compareTo(Object) Comparator - compare(Object, Object) String and Wrapper classes implement Comparable and equals() method StringBuffer/Builder do NOT implement Comparable and equals() method List li = new ArrayList(); for(Object : li) {} Iterator it = li.iterator() ListIterator it = li.listIterator() // legal // legal // legal

List<String> li = new ArrayList<String> (); for(String : li) {} Iterator<String> it = li.iterator() ListIterator<String> it = li.listIterator() // legal // legal // legal

You might also like