Question
import java.util.*;
class Output {
public static void main(String args[]) {
TreeSet t = new TreeSet();
t.add("3");
t.add("9");
t.add("1");
t.add("4");
t.add("8");
System.out.println(t);
}
}
What is the output of this program?
import java.util.*;
class Output {
public static void main(String args[]) {
TreeSet t = new TreeSet();
t.add("3");
t.add("9");
t.add("1");
t.add("4");
t.add("8");
System.out.println(t);
}
}
Answer: Option D
Was this answer helpful ?
TreeSet class uses set to store the values added by function add in ascending order
using tree for storage
Output:
$ javac Output.java
$ java Output
[1, 3, 4, 8, 9]
Was this answer helpful ?
Submit Solution