Maps

Cards (9)

  • Maps
    • dynamic data structure that stores key/value pairs
    • import java.util.Map
  • Hash map
    keys are unordered
  • Linked Hash map
    keys are ordered based on sequence elements were added
  • tree map
    keys are sorted
  • put key/value pair
    • adds a key-value pair to the map if the key is not already in the map and returns null
    • replaces the value associated with the key and returns the previous value associated with key
  • remove key/value pair
    • removes a key-value pair from the map if the key is in the map and returns the previous value associated with key
    • returns null if the key was not in the map
  • get value
    • returns the value associated with key if the key is in the map
    • returns null if the key was not in the map
  • size
    returns the number of key-value pairs in the map
  • for each
    • display all of the key-value pairs in the map
    • studentSortedMap.forEach( (key, value) ->{System.out.println(key + “: " + value);});