Question: 1) Does a TreeSet allow duplicate values to be added to the Set? For example, what happens if you try to execute the following code?

1) Does a TreeSet allow duplicate values to be added to the Set? For example, what happens if you try to execute the following code?

TreeSet myTree = new TreeSet(); myTree.add("alice"); myTree.add("alice"); a)This code is illegal and will cause a compile-time error message. B)This code will not have any compiler error message, but when you execute this code the program will "crash" and throw an Exception and the program will halt. c) This code is legal. The second (duplicate) add method will simply quietly ignore and discard the duplicate value. The value of myTree.size() will be 1 after this code is executed. d) This code is legal. The TreeSet will have two items in the Set (i.e., myTree.size() will be equal to 2), with the identical values.

2) Does a TreeSet allow the null value to be added into the Set?

For example, what happens if you try to execute the following code? TreeSet myTree = new TreeSet (); myTree.add("alice"); myTree.add(null);

a)This code is illegal and will cause a compile-time error message. b)This code will not have any compiler error message, but when you execute this code the program will "crash" and throw an Exception and the program will halt. c)This code is legal. The second add method will simply quietly ignore and discard the null value. The value of myTree.size() will be 1 after this code is executed. d)This code is legal. The TreeSet will have two items in the Set (i.e., myTree.size() will be equal to 2).

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!