CS 106A Lecture Notes - Lecture 26: Foreach Loop

28 views1 pages

Document Summary

Maps: map: a collection that stores pairs, first half of pair is called the key; second half is a value. We use the hashmap class to create a map in java (check slides for format) No primitive values in a hashmap: usage. No order associated with maps; just pairs of values stored in map. Add a key/value pair to the map. M. put(key, value): replaces any previous value for that key, keys in a map are case-sensitive. Look up a value by supplying a key. M. remove(key): cannot remove key + value or value. Other methods for map are in slides: animals hash map example. Call the map name and then put key and value into the map. Can also change values associated with a key in between commands. If the key does not exist in the map, it will set it as null. Cannot give the value and have it return the key.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents