1 / 21

Advanced Java Programming

Advanced Java Programming. CSS446 Spring 2014 Nan Wang. Chapter Goals. Java Collection Framework LinkedList Set Map. Collection. When you need to organize multiple objects in your program, you can place them into a collection.

mariawright
Download Presentation

Advanced Java Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advanced Java Programming CSS446 Spring 2014 Nan Wang

  2. Chapter Goals • Java Collection Framework • LinkedList • Set • Map

  3. Collection • 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

  4. Java Collections Framework • A hierarchy of interface types and classes for collecting objects. Each interface type is implemented by one or more classes.

  5. List • a list is a collection that remembers the order of its elements.

  6. ArrayList • 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. a a a a b b b b d d c c d e d e e f f e f f Insertion and Deletion of ArrayList element element element element

  8. Set • 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. Stack • 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. Bus Stop Queue • 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) front rear rear rear rear rear

  11. Map • A map keeps associations between key and value objects.

  12. LinkedList • 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. LinkedList – Insert and delete

  14. LinkedList Class • It is a generic class, that you specify the type of the list elements in angle brackets.

  15. List Iterators • 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. List Iterators • Obtain a list iterator with the listIterator() of the LinkedList class.

  17. Review Questions

More Related