public class BuggyBread1{<br /> <br /> public static void main (String args[]) {<br /> Set<Integer> mySet = new TreeSet<Integer>();<br /> mySet.add(1);<br /> mySet.add(2);<br /> mySet.add(111);<br /> for(Integer d: mySet){<br /> System.out.println(d);<br /> }<br /> }<br /> }
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers

 Q1. public class BuggyBread1{

public static void main (String args[]) {
Set<Integer> mySet = new TreeSet<Integer>();
mySet.add(1);
mySet.add(2);
mySet.add(111);
for(Integer d: mySet){
System.out.println(d);
}
}
}
Core Java
Ans. 1
2
111

TreeSet maintains the elements in the ascending order which is identified by the compareTo method. compareTo method in Integer has been defined such that it results in the natural numerical Order.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   code   coding   set   treeset


Related Questions

 Collections.sort can only be performed on ..

a. Set
b. List
c. Map
d. Any Collection implementation
 Difference beween HashSet and TreeSet ?
  What is the difference between List, Set and Map ?

or

What are the different Java Collections Interfaces ?
  What is comparator interface used for ?
  Why are Getter and Setter better than directly changing and retrieving fields ?

or

What is the significance of variable hiding in Java ?

or

Why it's preferred to keep variables private and allow their access through getter and setter methods ?
  If I try to add Enum constants to a TreeSet, What sorting order will it use ?
  In what order the elements of a HashSet are retrieved ?
  Which of the following doesn't extend Collection interface ?
  How to display and set the Class path in Unix ?
  Which are the sorted collections ?



Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: