Chapter 14
Upcoming SlideShare
Loading in...5
×
 

Chapter 14

on

  • 90 views

 

Statistics

Views

Total Views
90
Views on SlideShare
90
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Chapter 14 Chapter 14 Presentation Transcript

  • Map Collections and Custom Collection Classes Chapter 14
  • 14 Maps An object that maps a key to a value Key maps to one value A map cannot have duplicate keys Often used to associate a short key with a longer value Example: Dictionary Example: Employee database using employee ID number
  • 14 Concrete Map Implementations TreeMap orders the keys. HashMap stores the keys in a hash table. HashMap class is generally preferred for its efficiency (speed) unless sorted keys are needed.
  • 14 Retrieving Values by Key Use the keys collection to retrieve the keys in a map. Iterator keyIterator = myMap.keySet().iterator(); Keys collection holds “key” objects. Must cast key values to the appropriate type Integer key = (Integer)keyIterator.next(); Retrieves the next key from keyIterator (collection of keys) then casts it to an Integer and assigns it to the variable key
  • 14 Custom Collection Classes Custom collections allow you to define the data storage method. Good way to understand how other collection classes work Think through issues involved in writing good generic classes
  • 14 Linked List A linked list is a type of collection, similar to a train. Each object or node is linked to the next object in the collection. Singly linked list Each node knows the node following it Can only be iterated in one direction Doubly linked list Each node knows the node preceding it and the node following it Can be iterated in both directions
  • 14 Linked List Hierarchy Head node points to next node in list Internal node “carries” an object (the value being stored) and points to next node in list Tail node signals end of the list