Question: Question 51 pts Every key in a Map must be unique. What happens when a Map receives a 'put' message specifying a key that is

Question 51 pts

Every key in a Map must be unique. What happens when a Map receives a 'put' message specifying a key that is already used in the Map?

A DuplicateKeyException is thrown.
The map entry for the key is updated -- its associated value is replaced by the new value specified, and the old value is returned by the 'put' method.
The map entry for the key is updated -- its associated value is replaced by the new value specified, and null is returned by the 'put' method.
The map entry for the key is updated -- the new value specified is added to the list of values associated with the key.
No change is made to the Map, and the 'put' method returns null.

Flag this Question

Question 61 pts

Which of the following could be an "expensive" operation (an operation that takes a long time to complete) in an ArrayList?

adding a new item at the end of the list when size( ) is less than capacity
adding a new item at the beginning of the list
using get(itemNumber) to examine a list item in the middle of the list
iterating through the list

Flag this Question

Question 71 pts

Which of the following could be an "expensive" operation in the SimpleLinkedList class we discussed?

adding a new item at the end of the list
adding a new item at the beginning of the list
using get(itemNumber) to examine a list item in the middle of the list
calling 'next()' using an iterator provided by the list

Flag this Question

Question 81 pts

What will be the contents of myList, in the correct order, after the following sequence of operations? (Assume all operations are supported by the list implementation used.)

List myList = ... // create new, empty list  myList.add( "red" );  myList.add( "green" );  myList.add( "red" );  myList.add( 1, "black" );
[ "red", "green", "red", "black" ]
[ "black", "green", "red" ]
[ "red", "black", "green", "red" ]
[ "black", "red", "green" ]
[ "red", "black", "red" ]

Flag this Question

Question 91 pts

What will be the contents of mySet, regardless of order, after the following sequence of operations? (Assume all operations are supported by the set implementation used.)

Set mySet = ... // create new, empty set  mySet.add( "red" );  mySet.add( "green" );  mySet.add( "red" );  mySet.add( "black" );
[ "red", "green", "red", "black" ]
[ "black", "green", "red" ]
[ "green", "red" ]
[ "black" ]
[ "green", "black" ]

Flag this Question

Question 101 pts

What will be the contents of myMap, regardless of order, after the following sequence of operations? (Assume all operations are supported by the map implementation used.) Answers are shown as key=value pairs.

Map myMap = ... // create new, empty map  myMap.put( "red", "green" );  myMap.put( "orange", "blue" );  myMap.put( "red", "yellow" );  myMap.put( "blue", "black" );
[ "red"="green", "orange"="blue", "red"="yellow", "blue"="black" ]
[ "orange"="blue", "red"="yellow" ]
[ "red"="green", "orange"="blue" ]
[ "red"="yellow", "blue"="black" ]
[ "orange"="blue", "red"="yellow", "blue"="black" ]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!