Java - Interview Questions and Answers for 'Treemap' | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Java Interview Questions


 2098 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Treemap' - 14 question(s) found - Order By Newest

Very frequently asked. Favorite question in Walk in Drive of many Indian service companies.
  Q1. Difference between TreeMap and HashMap ?Core Java
Anonymous
Ans. They are different the way their elements are stored in memory. TreeMap stores the Keys in order whereas HashMap stores the key value pairs randomly.

  Sample Code for treemap

  Sample Code for hashmap

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

   Like      Discuss      Correct / Improve     java   collections   map   treemap   hashmap     Amber Road  CTS (Cognizant)  ION Trading  DataMetica  Accenture  The Advisory Board Company  BidGely  Infosys  Tata Consultancy (TCS)  HCL Technologies  Wipro  Booking.com  MakeMyTrip  Garena Online  Garmin  ION Trading  Accuity  Palantir Technologies  Books International  Wealthfront  Marin Software  Garmin  IBM  Global Logic  Fiserv  Cumulus Systems  CCTS  UST Global      basic        frequent

Try 1 Question(s) Test


 Q2. What is comparator interface used for ?Core Java
Admin
info@buggybread.com
Ans. The purpose of comparator interface is to compare objects of the same class to identify the sorting order. Sorted Collection Classes ( TreeSet, TreeMap ) have been designed such to look for this method to identify the sorting order, that is why class need to implement Comparator interface to qualify its objects to be part of Sorted Collections.

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

   Like      Discuss      Correct / Improve     java   collections   treemap   treeset   comparator     ZapCom  Verilogue      Intermediate

Try 2 Question(s) Test


 Q3. Which of the following collection maintain its elements in Natural Sorted order ?

a. HashMap
b. TreeMap
c. LinkedHashMap
d. LinkedMap
Anonymous
Ans. TreeMap

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

   Like      Discuss      Correct / Improve     treemap   collections   java   sorted collections   map


 Q4. Which are the sorted collections ?Core Java
Admin
info@buggybread.com
Ans. TreeSet and TreeMap

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

   Like      Discuss      Correct / Improve     java   collections   treemap   treeset   basic interview question      basic        frequent


 Q5. How can we reverse the order in the TreeMap ?
Admin
info@buggybread.com
Ans. Using Collections.reverseOrder()

Map tree = new TreeMap(Collections.reverseOrder());

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

   Like      Discuss      Correct / Improve     java   collections   map   treemap

Try 1 Question(s) Test


 Q6. TreeMap orders the elements on which field ?
Admin
info@buggybread.com
Ans. Keys

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

   Like      Discuss      Correct / Improve     java   collections   map   treemap


 Q7. How TreeMap orders the elements if the Key is a String ?
Admin
info@buggybread.com
Ans. As String implements Comparable, It refers to the String compareTo method to identify the order relationship among those elements.

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

   Like      Discuss      Correct / Improve     java   collections   comparable interface   treemap   compareto


 Q8. Can we add heterogeneous elements into TreeMap ?
Admin
info@buggybread.com
Ans. No, Sorted collections don't allow addition of heterogeneous elements as they are not comparable.

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

   Like      Discuss      Correct / Improve     java   collections   comparable interface   treemap


 Q9. Will it create any problem if We add elements with key as user defined object into the TreeMap ?
Admin
info@buggybread.com
Ans. It won't create any problem if the objects are comparable i.e we have that class implementing Comparable interface.

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

   Like      Discuss      Correct / Improve     java   collections   treemap   comparable interface



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



  Q10. Can we have null keys in TreeMap ?Core Java
Admin
info@buggybread.com
Ans. No, results in exception.

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

   Like      Discuss      Correct / Improve     java   collections   treemap     Visa  Prokarma  Sabre  Polaris  Deloitte  Cognizant (CTS)      Basic        frequent


 Q11. Can value be null in TreeMap ?Core Java
Admin
info@buggybread.com
Ans. Yes.

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

   Like      Discuss      Correct / Improve     java   collections   treemap   yes-no


 Q12. Which interface TreeMap implements ?
Admin
info@buggybread.com
Ans. TreeMap implements NavigableMap, SortedMap, Serializable and Clonable.

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

   Like      Discuss      Correct / Improve     java   collections   treemap


 Q13. Which tree is used to implement TreeMap in Java?
Admin
info@buggybread.com
Ans. Red Black Tree

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

   Like      Discuss      Correct / Improve     java   collections   treemap   map      expert


 Q14. If we add Enum constants to a sorted collection ( Treemap , TreeSet ), What will be the order in which they will be maintained ?

a. Sorted Collection wont maintain them in any order.
b. Insertion Order
c. Order in which constants are declared.
d. Natural Sorting Order.
Anonymous
Ans. Order in which constants are declared.

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

   Like      Discuss      Correct / Improve     enum   collections   sorted collections   treemap   treeset   compareto   comparable   java




Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

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:
         

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: