Core Java - Interview Questions and Answers for 'Treemap' - 17 question(s) found - Order By Rating Q1. Difference between TreeMap and SortedMap ? Core Java 2019-02-06 11:26:07
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  treemap  sortedmap Q2. How to sort objects based on one of the field ? Core Java 2018-07-04 16:23:09
Ans. Using comparable and comparator and sorted collections like TreeSet or TreeMap.
or
use stream api from java 8 onwards which internally refers to comparable and comparator through lambda expressions Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  sort  sorting  comprator  comparable  treeset  treemap  sorting collections Asked in 1 Companies Basic   frequent Q3. What is the difference between TreeSet and TreeMap ? Core Java 2018-06-27 09:56:39
Ans. TreeSet contains only values as elements whereas TreeMap contains Key value pairs. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  reeMap  TreeSet  Collections  sorted collection Asked in 1 Companies   rare Very frequently asked. Favorite question in Walk in Drive of many Indian service companies. Q4. 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 Asked in 31 Companies basic   frequent Try 1 Question(s) Test Q5. 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 Asked in 2 Companies Intermediate Try 2 Question(s) Test Q6. 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 Q7. 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 Q8. 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 Q9. 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 Q10. 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 Q11. 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 Q12. 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 Asked in 6 Companies Basic   frequent Q13. 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 Q14. 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 Q15. 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 Q16. 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 Q17. 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