Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.

Similar presentations


Presentation on theme: "CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2."— Presentation transcript:

1

2 CSS446 Spring 2014 Nan Wang

3  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2

4  When you need to organize multiple objects in your program, you can place them into a collection.  A collection groups together elements and allows them to be retrieved later.  ArrayList 3

5  A hierarchy of interface types and classes for collecting objects. Each interface type is implemented by one or more classes. 4

6 5

7  a list is a collection that remembers the order of its elements. 6

8  The ArrayList class implements the List interface.  An ArrayList is simply a class containing an array that is expanded as needed.  If you are not concerned about efficiency, you can use the ArrayList class whenever you need to collect objects. However, several common operations are inefficient with array lists. In particular, if an element is added or removed, the elements at larger positions must be moved. 7

9 8 abdefabcdef element abdefabcdef

10  Set is an unordered collection of unique elements.  Because a set does not track the order of the elements, so the operations of finding, adding and removing are more efficient. 9

11  A stack remembers the order of its elements, but it does not allow you to insert elements in every position.  You can add and remove elements only at the top. 10

12  In a queue, you add items to one end (the tail) and remove them from the other end (the head).  A priority queue is an unordered collection that has an efficient operation for removing the element with the highest priority. (reading assignments) 11 Bus Stop front rear

13  A map keeps associations between key and value objects. 12

14  A linked list uses a sequence of nodes.  A node is an object that stores an element and references to the neighboring nodes in the sequence 13

15 14

16  It is a generic class, that you specify the type of the list elements in angle brackets. 15

17  List iterators are used to access elements inside a linked list.  you should think of the iterator as pointing between two elements, just as the cursor in a word processor points between two characters 16

18  Obtain a list iterator with the listIterator() of the LinkedList class. 17

19 18

20 19

21 20

22 21


Download ppt "CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2."

Similar presentations


Ads by Google