Home » JAVA Programming » Collections » Question
  1. What is the output of this program?
    import java.util.*; 
    public class TreeSet_Example
    {
    public static void main(String args[])
    {
    TreeSet object = new TreeSet();
    object.add("7");
    object.add("0");
    object.add("9");
    object.add("5");
    object.add("6");
    System.out.println(object);
    }
    }
    1. Runtime Error
    2. Compilation Error
    3. [0, 5, 6, 7, 9]
    4. [6, 7, 9]
    5. [0, 5, 6, 7]
Correct Option: C

TreeSet class uses set to store the values added by function add in ascending order using tree for storage



Your comments will be displayed only after manual approval.