Analyze the following code import java util ; public class Test{pu
Analyze the following code. import java.util.*; public
class Test{public static void main(String[] args) throwsE
xception {Treesetset – new Treeset0; set add(\”Red\”);
set add(\”Yellow\”); set add(\”Green\”), set add(\”Blue\”);
SortedSet temp = setheadset(\”Purple\”);
System.out.println(temp.first();}} A. The program displays
Red B. The program displays Blue C. The program
displays Green D. The program displays Yellow E. The
program displays Purple if you want to store non duplicated objects in the order in which they are inserted,
you should use___. A. HashSet B. LinkedHashSet C.
TreeSet D. ArrayList E. LinkedList Suppose set s1 is[1, 2,
5] and set s2 is [2, 3, 6]. After s1.addAll(s2), s1 is___ A.
[1, 2, 2, 3, 5, 6] B. [1, 2, 3, 5, 6] C . [1, 5] D. [2] Which
of the following operations are supported by a list? A.
Retrieve an element from this list. B. Insert a new
element to this list. C. Delete an element from this list.
D. Find how many elements are in this list. E. Find
whether an element is in this list.
Solution
Answer for 34: option B —> The program displays Blue
Basically we are displaying the first element of the sorted
tree set in this program. Hence the program will display
blue
Answer for 35: option B —> LinkedHashSet
It is a hastable and linked list implementation of the set
interface that contains unique elements and maintains
order.
Answer for 36: Option B —> [1, 2, 3, 5, 6]—> addAll
adds all the specified elements to the specified collection.
Here it is a set which maintains unique elements. Hence
the output will be unique elements after addAll operation.
Answer for 37: Option A, B , C, D, E —-> All the options
are valid because list supports all the methods mentioned
in the options.
Name:
Description:
…