Download presentation
Presentation is loading. Please wait.
1
CSE 1020: The Collection Framework
Mark Shtern
2
Summary Inheritance
3
Main Interfaces List Set Map Sequence Duplicate are allowed
Duplicate are not allowed Order is insignificant Map Mapping between set of keys and set of values Mapping must be a function
4
Storage Techniques Hash Array Tree Linked
5
Implementing Classes List ArrayList, LinkedList
Set HashSet, TreeSet Map HashMap, TreeMap
6
Default List ArrayList Set HashSet Map HashMap
7
Example output.println(“Enter the elements pressing Enter “); output.println(“after each. [Empty line = sentinel]”); for (String in = input.nextLine(); in.length() !=0; in = input.nextLine()) { if (!bag.add(in)) { output.println(“Not added (already present)”); }
8
Generics List bag = new ArrayList(); bag.add(“testing”); List <Date> bag = new ArrayList<Date>(); <? extends P> or <? super C>
9
API Highlights Adding elements Removing elements boolean ddd (E o)
V put (K key, V value) add (int index, E element) Removing elements boolean remove (Object o) E remove (int index) V remove (K key)
10
API Highlights Accessing Elements Searching E get(int index)
V get(K key) Searching contains(E o) conatinsKey(K key)
11
Iteration for(String x: bag.keySet()) { .... } for(String x: bag)
12
Searching and Sorting Collections sort (List<T> list)
binarySearch(List<? Extends T> list, T x)
13
Detection Duplicate Problem: Given a list of integers, determine whether its element are distinct List Approach 1 Approach 2 Set
14
Word Frequency How do you extract words from a sentence?
Map word and its counter
15
Sorting Map TreeMap keeps the elements sorted on the keys
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.