[YOSHIHIRO KOBAYASHI] COMPLETE QUESTIONS AND VERIFIED
ANSWERS
1. Assume that you have declared a set named mySet to hold String
elements. Which of the following statements will correctly insert an
element into mySet?
a) mySet.put(apple");
b) mySet.insert("apple");
c)mySet.add("apple");
d) mySet.push("apple");: c
2. Assume that you have declared a set named mySet to hold String
elements. Which of the following statements will correctly delete an
element from my- Set?
a) mySet.delete("apple");
b) mySet.remove("apple");
c)mySet.get("apple");
d) mySet.pop("apple");: b
3. Assume that you have declared a map named myMap to hold
String values with Integer keys. Which of the following statements
will correctly add an association into myMap?
a) myMap.insert(3, "apple");
b) myMap.add(3, "apple");
c)myMap.put(3, "apple");
d) myMap.push(3, "apple");: c
4. Which of the following statements about manipulating
objects in a map is NOT correct?
a) Use the remove method to remove a value from the map.
b) Use the get method to retrieve a value from the map.
c)Use the keyset method to get the set of keys for the map.
d) Use the add method to add a new element to the map.: d
5. Assume that you have declared a map named myMap to hold
String values with Integer keys. Which of the following
statements will correctly delete an association from myMap?
a) myMap.remove(3);
, CSE 205 EXAM #3 (HANDOUTS 10-15 & QUIZES 8-11)
[YOSHIHIRO KOBAYASHI] COMPLETE QUESTIONS AND VERIFIED
b) myMap.remove("apple"); ANSWERS
, CSE 205 EXAM #3 (HANDOUTS 10-15 & QUIZES 8-11)
[YOSHIHIRO KOBAYASHI] COMPLETE QUESTIONS AND VERIFIED
c)myMap.delete(3); ANSWERS
d) myMap.pop(3);: a
6. Assume that you have declared a map named myMap to hold
String values with Integer keys. Which of the following statements
will correctly retrieve the value associated with a key from
myMap?
a) myMap.peek(3);
b) myMap.get("apple");
c)myMap.peek("apple");
d) myMap.get(3);: d
7. Which of the following statements about manipulating
objects in a map is NOT correct?
a) Use the put method to add an element to the map.
b) If you attempt to retrieve a value with a key that is not
associated with any value, you will receive a null result.
c)Use the get method to retrieve a value associated with a key in the
map.
d) You cannot change the value of an existing association in the
map; you must delete it and re-add it with the new values.: d
8. Consider the following code snippet:
Map<String, Integer> scores;
If you need to visit the keys in sorted order, which of the following
statements will create a structure to support this?
a) scores = new HashTable<>;
b) scores = new HashMap<>;
c)scores = new TreeMap<>;
d) scores = new Map<>;: c
9. Consider the following code snippet:
Map<String, Integer> scores;
You expect to retrieve elements randomly by key, and want fastes
retrieval times. Which of the following statements will create a
, CSE 205 EXAM #3 (HANDOUTS 10-15 & QUIZES 8-11)
[YOSHIHIRO KOBAYASHI] COMPLETE QUESTIONS AND VERIFIED
structure to support this? ANSWERS
a) scores = new HashMap<>;
b) scores = new Map<>;