Ja Java va Co Coll llection ection Fra ramew ework
- rk
Version March 2009
Ja Java va Co Coll llection ection Fra ramew ework ork - - PowerPoint PPT Presentation
Ja Java va Co Coll llection ection Fra ramew ework ork Version March 2009 Framework Interfaces (ADT, Abstract Data Types) Implementations (of ADT) Algorithms (sort) java.util.* Java 5 released! Lots of changes about
Version March 2009
2
3
Collection<E> Set<E> List<E> Map<K,V> SortedSet<E> SortedMap<K,V> Group containers Associative containers Queue<E> Iterable<E>
4
TreeSet TreeMap Array List Linked List HashMap Linked HashMap Linked HashSet HashSet Map<K,V> Sorted Map<K,V> Collection<E> Set<E> List<E> Sorted Set<E> Queue<E> Priority Queue
5
LinkedList Linked list LinkedHashMap TreeMap HashMap Map ArrayList List LinkedHashSet TreeSet HashSet Set Hash table Linked list Balanced tree Resizable array Hash table
interface data structure classes
6
7
8
9
10
11
12
13
14
Collection<E> Set<E> List<E> SortedSet<E> Queue<E>
16
17
18
19
ArrayList() ArrayList(int initialCapacity) ArrayList(Collection c) void ensureCapacity(int minCapacity)
void addFirst(Object o) void addLast(Object o) Object getFirst() Object getLast() Object removeFirst() Object removeLast()
20
21
Car[] garage = new Car[20]; garage[0] = new Car(); garage[1] = new ElectricCar(); garage[2] = new ElectricCar(); garage[3] = new Car(); for(int i=0; i<garage.length; i++){ garage[i].turnOn(); }
List<Car> garage = new ArrayList<Car>(20); garage.set( 0, new Car() ); garage.set( 1, new ElectricCar() ); garage.set( 2, new ElectricCar() ); garage.set( 3, new Car()); for(int i; i<garage.size(); i++){ Car c = garage.get(i); c.turnOn(); }
22
bounds
extended
23
24
25
26
32
33
34
Map<K,V> SortedMap<K,V>
36
37
38
39
41
42
43
44
45
46
47
for(Iterator i= persons.iterator(); i.hasNext(); ) {
48
49
50
51
52
53
54
56
57
58
59
60
61
62
63
65
66
67
68
students.add(new Student(“Mary”,“Smith”,34621)); students.add(new Student(“Alice”,“Knight”,13985)); students.add(new Student(“Joe”,“Smith”,95635));
69
70
71