Q. What will be the output of the following code

Code:
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

public class SortSet {
public static void main(String…a)
{
Collection<Integer> collection = new HashSet<Integer>();
collection.add(3);
collection.add(1);
collection.add(2); {

Set<Integer> treeSet=new TreeSet<Integer>(collection);
System.out.println(treeSet);

}
}
}
  • (A) [1, 2, 3]
  • (B) Runtime exception
  • (C) [3, 2, 1]
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (A) [1, 2, 3]

You must be Logged in to update hint/solution

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
272
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Pradeep Sikarwar
Publisher
πŸ“ˆ
84%
Success Rate