{"id":1026,"date":"2016-03-09T05:43:56","date_gmt":"2016-03-09T05:43:56","guid":{"rendered":"http:\/\/abhiandroid.com\/java\/?p=1026"},"modified":"2016-03-09T05:50:13","modified_gmt":"2016-03-09T05:50:13","slug":"treemap-methods","status":"publish","type":"post","link":"https:\/\/abhiandroid.com\/java\/treemap-methods.html","title":{"rendered":"TreeMap Methods Tutorial With Examples in JAVA"},"content":{"rendered":"<p>TreeMap store values based on \u00a0key value pairs. This pair is often called as Entry.\u00a0It \u00a0stores only unique elements\u00a0i.e.\u00a0duplicate values are not allowed and it cannot store key as <strong>null<\/strong> but can store<strong> null <\/strong>values. Mostly it is similar to HashMap Class and key difference is,\u00a0it maintains an increasing order of the values based on the keys.<\/p>\n<hr \/>\n<h4><strong>TreeMap\u00a0Methods in JAVA<\/strong><\/h4>\n<p>Let us discuss all the TreeMap\u00a0methods one by one with Examples in Java.<\/p>\n<p><span style=\"color: #008000;\"><strong>1 .\u00a0Object \u00a0ceilingEntry(Object key)<\/strong><\/span><\/p>\n<p>This method returns a Entry with the \u00a0least key greater than or equal to the given key in the argument list, or null if there is no such key, as shown in the following program<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\u00a0\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(98,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\u00a0\r\nSystem.<em>out<\/em>.println(\"Ceiling entry for 99: \"+ tm.ceilingEntry(99));\r\n\r\nSystem.<em>out<\/em>.println(\"Ceiling entry for 103: \"+ tm.ceilingEntry(103));\r\n\r\n}\r\n\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Ceiling entry for 99: 100=I\r\n\r\nCeiling entry for 103: 103=Java\r\n\r\n<\/pre>\n<p>In the output we see ceiling value of key \u201c99\u201d is \u201c100\u201d as we see 99 is not present in treemap, it automatically tool least greater than \u201c99\u201d which is \u201c100\u201d.\u00a0And Ceiling value of \u201c103\u201d is \u201c103\u201d, which we see is present in the given map.<\/p>\n<p><span style=\"color: #008000;\"><strong>2.\u00a0Object ceilingKey(Object key)<\/strong><\/span><\/p>\n<p>This method returns a key with the\u00a0 least key greater than or equal to the given key in the argument list, or null if there is no such key, This method is same as ceilingEntry(Object key) , only difference is it returns only key, as shown in the following program<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\u00a0\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(98,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\nSystem.<em>out<\/em>.println(\"Ceiling key for 99: \"+ tm.ceilingKey(99));\r\n\r\nSystem.<em>out<\/em>.println(\"Ceiling key for 103: \"+ tm.ceilingKey(103));\r\n\r\n}\r\n\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Ceiling key for 99: 100\r\n\r\nCeiling key for 103: 103\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong> 3.\u00a0void clear()<\/strong><\/span><\/p>\n<p>This method removes all the entries from the TreeMap object as shown<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\u00a0\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(102,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\nSystem.<em>out<\/em>.println(\"TreeMap before : \" + tm);\r\n\r\ntm.clear();\r\n\r\nSystem.<em>out<\/em>.println(\"TreeMap After clear method: \" + tm);\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>TreeMap before : {100=I, 101=Love, 102=Core, 103=Java}\r\n\r\nTreeMap After clear method: {}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>4.\u00a0Object clone()<\/strong><\/span><\/p>\n<p>This method returns a duplicate copy of the TreeMap object, as shown in the following program<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm1 =new TreeMap&lt;Integer,String&gt;();\r\n\r\nTreeMap&lt;Integer, String&gt; tm2 = new TreeMap&lt;Integer, String&gt;();\r\n\r\ntm1.put(102,\"Core\");\r\n\r\ntm1.put(100,\"I\");\r\n\r\ntm1.put(103,\"Java\");\r\n\r\ntm1.put(101,\"Love\");\r\n\r\n\/\/using clone method\r\ntm2 =(TreeMap) tm1.clone();\r\n\r\nSystem.<em>out<\/em>.println(\"Before using Clone method: \"+ tm1);\r\n\r\nSystem.<em>out<\/em>.println(\"After using Clone method: \"+ tm2);\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Cloning tree map\r\n\r\nBefore using Clone method: {100=I, 101=Love, 102=Core, 103=Java}\r\n\r\nAfter using Clone method: {100=I, 101=Love, 102=Core, 103=Java}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>5. Comparator comparator()<\/strong><\/span><\/p>\n<p>This method gives the comparator used in the map, which basically means in what ordering our map has data entries stored, If it returns null means given map is using natural ordering.<\/p>\n<p>Let us use this in our program, and check which ordering our TreeMap has.<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\u00a0\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(98,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\n\/\/ using comparator\r\n\r\nComparator comparator = tm.comparator();\r\n\r\nSystem.<em>out<\/em>.println(\"Comparator value: \"+ comparator);\r\n\r\n}\r\n\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Comparator value: null\r\n\r\nFrom output it is very clear that TreeMap uses Natural ordering.\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>6.\u00a0boolean containsKey(Object key)<\/strong><\/span><\/p>\n<p>This method checks whether the given\u00a0 TreeMap have the value at the specified key ,It returns true it is, or else returns false, as shown in the following program<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm =new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(102,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\nSystem.<em>out<\/em>.println(\"Checking whether there is value at key 101 \"+ \u00a0tm.containsKey(101));\r\n\r\nSystem.<em>out<\/em>.println(\"Checking whether there is value at key 105 \"+ tm.containsKey(105));\r\n}\r\n\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Checking whether there is value at key 101 true\r\n\r\nChecking whether there is value at key 105 false<\/pre>\n<p><span style=\"color: #008000;\"><strong> 7. boolean containsValue(Object value)<\/strong><\/span><\/p>\n<p>This method checks whether the given\u00a0 TreeMap have the value specified in the method,It returns true it is, or else returns false, as shown in the following program<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\n\u00a0\r\n\r\nTreeMap&lt;Integer,String&gt; tm =new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(102,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\n\/\/using ContainsValue method\r\n\r\nSystem.<em>out<\/em>.println(\"IF India exists: \"+ tm.containsValue(\"India\"));\r\n\r\nSystem.<em>out<\/em>.println(\"IF Java exists: \"+ tm.containsValue(\"Java\"));\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>IF India exists: false\r\n\r\nIF Java exists: true\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>8.\u00a0Object \u00a0descendingKeySet()<\/strong><\/span><\/p>\n<p>This method returns descending order of the all the keys stored in the treemap, In the following program we are creating object of NavigableSet class and we are storing all values in this first, than we are calling descendingKeySet() method, as shown in the following program.<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(98,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\n\/\/putting values in navigable set\r\n\r\nNavigableSet navigableset=tm.descendingKeySet();\r\n\r\n\u00a0\r\nSystem.<em>out<\/em>.println(\"Values after using descending key Set method: \"+navigableset);\r\n}\r\n\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Values after using descending key Set method: [103, 101, 100, 98]\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>9.\u00a0NavigableMap \u00a0descendingMap()<\/strong><\/span><\/p>\n<p>This method returns descending order of the all the entries stored in the treemap, In the following program we are creating object of NavigableMap class and we are storing all values in this first, than we are calling descendingMap() method, as shown in the following program.<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(98,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\n\/\/putting values in navigable map\r\n\r\nNavigableMap navigablemap=tm.descendingMap() ;\r\n\r\nSystem.<em>out<\/em>.println(\"Values after using descending map method: \"+navigablemap);\r\n}\r\n\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Values after using descending map method: {103=Java, 101=Love, 100=I, 98=Core}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>10.\u00a0Set entrySet()<\/strong><\/span><\/p>\n<p>This method returns a Set of all the Entries in ascending key order present In the TreeMap object, as shown in the following program<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm =new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(102,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\n\/\/using entrySet method\r\n\r\nSet mapset=treemap.entrySet();\r\n\r\nSystem.<em>out<\/em>.println(\"Set values: \"+mapset);\r\n\r\n}\r\n\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Set values: [100=I, 101=Love, 102=Core, 103=Java]\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>11. Object firstEntry()<\/strong><\/span><\/p>\n<p>This method as the name suggests returns the first entry entered into the Treemap, that is the lowest entry in the treemap, as shown in the following program<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(98,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\nSystem.<em>out<\/em>.println(\"First entry is: \"+ tm.firstEntry());\r\n\r\n}\r\n\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>First entry is: 98=Core\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>12. Object firstKey()<\/strong><\/span><\/p>\n<p>This method as the name suggests returns the first key entered into the Treemap, that is the lowest key in the treemap ,as shown in the following program<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(102,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\nSystem.<em>out<\/em>.println(\"First key is: \"+ tm.firstKey());\r\n\r\n}\r\n\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>First key is: 100\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>13. Object floorEntry(Object key)<\/strong><\/span><\/p>\n<p>This method returns an entry with greatest key less than or equal to the key mentioned in the argument, or null if there is no such key, Let us discuss it by taking some key in a program , as shown below.<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(98,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\n\r\nSystem.<em>out<\/em>.println(\"floor entry for '102' is: \"+ tm.floorEntry(102));\r\n\r\nSystem.<em>out<\/em>.println(\"floor entry for '99' is:\"+ tm.floorEntry(99));\r\n\r\nSystem.<em>out<\/em>.println(\"floor entry for '100' is:\"+ tm.floorEntry(100));\r\n\r\n}\r\n\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>floor entry for '102' is: 101=Love\r\n\r\nfloor entry for '99' is:98=Core\r\n\r\nfloor entry for '100' is:100=I\r\n<\/pre>\n<p>As we can see in output , floor entry for \u201c102\u201d is \u201c101\u201d because 102 is not present , it will automatically give \u201c101\u201d that is\u00a0 greatest key less than or equal to given key , same is the case with key value \u201c99\u201d, And when we entered key \u201c100\u201d, as it is present it gives the same key as output.<\/p>\n<p><span style=\"color: #008000;\"><strong>14.\u00a0Object floorKey(Object key)<\/strong><\/span><\/p>\n<p>This method returns the greatest key less than or equal to the given key in the argument, or null if there is no such key, this method is same as floorEntry(), only difference is it gives only key but not key-value pair, as shown in following program.<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(98,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\nSystem.<em>out<\/em>.println(\"floor Key for '102' is: \"+ tm.floorKey(102));\r\n\r\nSystem.<em>out<\/em>.println(\"floor Key for '99' is:\"+ tm.floorKey(99));\r\n\r\nSystem.<em>out<\/em>.println(\"floor Key for '100' is:\"+ tm.floorKey(100));\r\n\r\n}\r\n\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>floor Key for '102' is: 101\r\n\r\nfloor Key for '99' is:98\r\n\r\nfloor Key for '100' is:100\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>15. Object get(Object key)<\/strong><\/span><\/p>\n<p>This methods returns the value associated with the mentioned key in the argument list, It return null if there is no mapping present, as shown in the following program<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(102,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\nSystem.<em>out<\/em>.println(\"Value at 103 is: \"+ tm.get(103));\r\n\r\n}\r\n\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Value at 103 is: Java\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>16. SortedMap headMap(Object toKey)<\/strong><\/span><\/p>\n<p>This method returns the part of the treemap whose key value is less than the mentioned value in the argument list, as shown in the program, we have taken a Sorted Map and used this method to store the values strictly below key 103.<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\u00a0\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\nSortedMap&lt;Integer, String&gt; tmhead = new TreeMap&lt;Integer, String&gt;();\r\n\u00a0\r\ntm.put(102,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\n\/\/getting head map\r\n\r\ntmhead=tm.headMap(103);\r\n\r\nSystem.<em>out<\/em>.println(\"Value below the headMap is: \"+ tmhead);\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Value below the headMap is: {100=I, 101=Love, 102=Core}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>17.\u00a0NavigableMap\u00a0 headMap(Object toKey, boolean inclusive)<\/strong><\/span><\/p>\n<p>This method returns a portion of map, whose key value is less than the value mentioned in the first argument, It is very much similar to the SortedMap headMap(Object toKey) method, only difference is return type and we have Boolean value , when it is true it will include the key mentioned in the program in the output, as shown in the following program.<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\nNavigableMap&lt;Integer, String&gt; navigableMap1 = new TreeMap&lt;Integer, String&gt;();\r\n\r\nNavigableMap&lt;Integer, String&gt; navigableMap2 = new TreeMap&lt;Integer, String&gt;();\r\n\u00a0\r\ntm.put(98,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\n\/\/ getting head map inclusive 3\r\n\r\nnavigableMap1=tm.headMap(101,true);\r\n\r\nnavigableMap2=tm.headMap(101,false);\r\n\r\nSystem.<em>out<\/em>.println(\"Checking values of the map\");\r\n\r\nSystem.<em>out<\/em>.println(\"Values when Boolean is True \"+ navigableMap1);\r\n\r\nSystem.<em>out<\/em>.println(\"Values when Boolean is False \"+ navigableMap2);\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output<\/strong><\/span>:<\/p>\n<pre>Checking values of the map\r\n\r\nValues when Boolean is True {98=Core, 100=I, 101=Love}\r\n\r\nValues when Boolean is False {98=Core, 100=I}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>18.\u00a0Object higherEntry(Object key)<\/strong><\/span><\/p>\n<p>This method returns the the entry with least key which is strictly greater than the given key in argument list, or null if there is no such key, as shown in following program.<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(98,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\nSystem.<em>out<\/em>.println(\"Higher Entry then '95': \"+ tm.higherEntry(95));\r\n\r\nSystem.<em>out<\/em>.println(\"Higher Entry then '100':\"+ tm.higherEntry(100));\r\n\r\nSystem.<em>out<\/em>.println(\"Higher Entry then '103': \"+ tm.higherEntry(103));\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Higher Entry then '95': 98=Core\r\n\r\nHigher Entry then '100':101=Love\r\n\r\nHigher Entry then '103': null\r\n<\/pre>\n<p>As shown in output, higher key than \u201c95\u201d\u00a0 is\u00a0 \u201c98\u201d as we are getting in output, same with key \u201c100\u201d, and there is no higher key than \u201c103\u201d , so output is null.<\/p>\n<p><span style=\"color: #008000;\"><strong>19.\u00a0Object higherKey(Object key)<\/strong><\/span><\/p>\n<p>This method returns the key with which is strictly greater than the given key in argument list, or null if there is no such key, as shown in following program.<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(98,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\nSystem.<em>out<\/em>.println(\"Higher Key then '95': \"+ tm.higherKey(95));\r\n\r\nSystem.<em>out<\/em>.println(\"Higher Key then '100':\"+ tm.higherKey(100));\r\n\r\nSystem.<em>out<\/em>.println(\"Higher Key then '103': \"+ tm.higherKey(103));\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Higher Key then '95': 98\r\n\r\nHigher Key then '100':101\r\n\r\nHigher Key then '103': null\r\n<\/pre>\n<p>As shown in output, higher key than \u201c95\u201d\u00a0 is\u00a0 \u201c98\u201d as we are getting in output, same with key \u201c100\u201d, and there is no higher key than \u201c103\u201d , so output is null.<\/p>\n<p><span style=\"color: #008000;\"><strong>20. Set keySet()<\/strong><\/span><\/p>\n<p>This method returns a Set view of all the keys stored in the treeMap as shown in the following program<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\u00a0\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\nSortedMap&lt;Integer, String&gt; tmhead = new TreeMap&lt;Integer, String&gt;();\r\n\r\ntm.put(102,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\nSet set=tm.keySet();\r\n\r\nSystem.<em>out<\/em>.println(\"Values of key Set is: \"+set);\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Values of key Set is: [100, 101, 102, 103]\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>21. Object lastEntry()<\/strong><\/span><\/p>\n<p>This method as the name suggests returns the last entry or we can say highest entry present in the tree map as shown in the following program<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(98,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\nSystem.<em>out<\/em>.println(\"Value of last entry: \"+ tm.lastEntry());\r\n}\r\n}\r\n<\/pre>\n<p>Output:<\/p>\n<pre>Value of last entry: 103=Java\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>22. Object lastKey()<\/strong><\/span><\/p>\n<p>This method as the name suggests returns the last key or we can say highest key present in the tree map as shown in the following program<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\nSortedMap&lt;Integer, String&gt; tmhead = new TreeMap&lt;Integer, String&gt;();\r\n\r\ntm.put(102,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\nSystem.<em>out<\/em>.println(\"Value of last key is: \"+ tm.lastKey());\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Value of last key is: 103\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>23.\u00a0Object\u00a0 lowerEntry(Object key)<\/strong><\/span><\/p>\n<p>This method returns an entry with the greatest key that is strictly less than the given key in argument, or null if there is no such key, as shown in the following program.<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(98,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\n\/\/ getting lower entry\r\n\r\nSystem.<em>out<\/em>.println(\"Lower Entry than '103' is: \"+ tm.lowerEntry(103));\r\n\r\nSystem.<em>out<\/em>.println(\"Lower Entry than '98' is: \"+ tm.lowerEntry(98));\r\n}\r\n\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Lower Entry than '103' is: 101=Love\r\n\r\nLower Entry than '98' is: null\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>24. Object lowerKey(Object key)<\/strong><\/span><\/p>\n<p>This method returns the greatest key that is strictly less than the given key in argument, or null if there is no such key, as shown in the following program.<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(98,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\n\/\/ getting lower key\r\n\r\nSystem.<em>out<\/em>.println(\"Lower Key than '103' is: \"+ tm.lowerKey(103));\r\n\r\nSystem.<em>out<\/em>.println(\"Lower Key than '98' is: \"+ tm.lowerKey(98));\r\n}\r\n\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Lower Key than '103' is: 101\r\n\r\nLower Key than '98' is: null\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>25.\u00a0NavigableSet navigableKeySet()<\/strong><\/span><\/p>\n<p>This method returns a set of all the keys in the TreeMap, as shown in the following program.<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(98,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\nSystem.<em>out<\/em>.println(\"Value of Navigable Key Set: \"+ tm.navigableKeySet());\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>\u00a0Value of Navigable Key Set: [98, 100, 101, 103]\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>26.\u00a0Object pollFirstEntry()<\/strong><\/span><\/p>\n<p>This method returns the lowest value corresponding to the value of key, and it also removes that value from the map, if the map is empty, than it return null, as shown in the following program.<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(98,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\nSystem.<em>out<\/em>.println(\"Value before using poll First Entry Method: \"+ tm);\r\n\r\nSystem.<em>out<\/em>.println(\"Calling Poll First Entry: \"+ tm.pollFirstEntry());\r\n\r\nSystem.<em>out<\/em>.println(\"Value After using poll First Entry Method : \"+ tm);\r\n\r\ntm.clear();\r\n\r\nSystem.<em>out<\/em>.println(\"Calling Poll First Entry After clearing the map: \"+ tm.pollFirstEntry());\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Value before using poll First Entry Method: {98=Core, 100=I, 101=Love, 103=Java}\r\n\r\nCalling Poll First Entry: 98=Core\r\n\r\nValue After using poll First Entry Method : {100=I, 101=Love, 103=Java}\r\n\r\nCalling Poll First Entry After clearing the map: null\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>27.\u00a0Object pollLastEntry()<\/strong><\/span><\/p>\n<p>This method returns the highest value corresponding to the value of key, and it also removes that value from the map, if the map is empty, than it return null, as shown in the following program.<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(98,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\nSystem.<em>out<\/em>.println(\"Value before using poll Last Entry Method: \"+ tm);\r\n\r\nSystem.<em>out<\/em>.println(\"Calling Poll Last Entry: \"+ tm.pollLastEntry());\r\n\r\nSystem.<em>out<\/em>.println(\"Value After using poll Last Entry Method : \"+ tm);\r\n\r\ntm.clear();\r\n\r\nSystem.<em>out<\/em>.println(\"Calling Poll Last Entry After clearing the map: \"+ tm.pollLastEntry());\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Value before using poll Last Entry Method: {98=Core, 100=I, 101=Love, 103=Java}\r\n\r\nCalling Poll Last Entry: 103=Java\r\n\r\nValue After using poll Last Entry Method : {98=Core, 100=I, 101=Love}\r\n\r\nCalling Poll Last Entry After clearing the map: null\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>28. Object put(Object key, Object value)<\/strong><\/span><\/p>\n<p>This method adds the specified value corresponding to the key ,If key mentioned is already present in the treemap , than it replaces it with new value that is mentioned in the argument, as shown in the followingprogram<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(102,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\ntm.put(104,\"hi\");\r\n\r\nSystem.<em>out<\/em>.println(\"Treemap :\" +tm);\r\n\r\ntm.put(103,\"India\") ;\r\n\r\nSystem.<em>out<\/em>.println(\"Treemap :\" +tm);\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Treemap :{100=I, 101=Love, 102=Core, 103=Java, 104=hi}\r\n\r\nTreemap :{100=I, 101=Love, 102=Core, 103=India, 104=hi}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>29. void putAll(Map map)<\/strong><\/span><\/p>\n<p>This method copies all of the entries from the mentioned treemap to the calling treemap, It maintains the ascending order of the keys as shown in the following program<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\nTreeMap&lt;Integer, String&gt; tm2 = new TreeMap&lt;Integer, String&gt;();\r\n\r\ntm.put(102,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(108,\"Java\");\r\n\r\ntm.put(105,\"Love\");\r\n\r\ntm2.put(101, \"I\");\r\n\r\ntm2.put(103, \"Love\");\r\n\r\ntm2.put(109, \"India\");\r\n\u00a0\r\ntm.putAll(tm2);\r\n\r\nSystem.<em>out<\/em>.println(\"Values after using putAll method:\" +tm);\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Values after using putAll method:{100=I, 101=I, 102=Core, 103=Love, 105=Love, 108=Java, 109=India}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>30. Object remove(Object key)<\/strong><\/span><\/p>\n<p>This method returns and removes the value for the key mentioned in the argument list from the TreeMap if it is present, as shown in the following program<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(102,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(108,\"Java\");\r\n\r\ntm.put(105,\"Love\");\r\n\u00a0\r\nSystem.<em>out<\/em>.println(\"Value before: \"+ tm);\r\n\r\n\/\/ removing value at key 102\r\n\r\nSystem.<em>out<\/em>.println(\"Removed value: \"+tm.remove(102));\r\n\r\nSystem.<em>out<\/em>.println(\"Value after : \"+ tm);\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Value before: {100=I, 102=Core, 105=Love, 108=Java}\r\n\r\nRemoved value: Core\r\n\r\nValue after : {100=I, 105=Love, 108=Java}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>31.\u00a0int size()<\/strong><\/span><\/p>\n<p>This method returns the number of entries in the treeMap, as shown in the following program<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(102,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(108,\"Java\");\r\n\r\ntm.put(105,\"Love\");\r\n\r\nSystem.<em>out<\/em>.println(\"Size of the map: \"+tm.size());\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Size of the map: 4\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>32.\u00a0NavigableMap \u00a0subMap(Object fromKey, boolean fromInclusive, Object toKey, boolean toInclusive)<\/strong><\/span><\/p>\n<p>This method returns group of entries of this map whose keys range from fromKey to toKey, If \u201cfromInclusive\u201d value is true , it will include that key value pair, same is the case with toinclusive, As shown in the following program<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\u00a0\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\nNavigableMap&lt;Integer, String&gt; nm1 = new TreeMap&lt;Integer, String&gt;();\r\n\r\nNavigableMap&lt;Integer, String&gt; nm2 = new TreeMap&lt;Integer, String&gt;();\r\n\r\nNavigableMap&lt;Integer, String&gt; nm3 = new TreeMap&lt;Integer, String&gt;();\r\n\r\nNavigableMap&lt;Integer, String&gt; nm4 = new TreeMap&lt;Integer, String&gt;();\r\n\r\ntm.put(98,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\nnm1=tm.subMap(98, true, 103, true);\r\n\r\nnm2=tm.subMap(98, false, 103, false);\r\n\r\nnm3=tm.subMap(98, true, 103, false);\r\n\r\nnm4=tm.subMap(98, false,103, true);\r\n\u00a0\r\nSystem.<em>out<\/em>.println(\"values of Navigable Map 1: \"+nm1);\r\n\r\nSystem.<em>out<\/em>.println(\"values of Navigable Map 2: \"+nm2);\r\n\r\nSystem.<em>out<\/em>.println(\"values of Navigable Map 3: \"+nm3);\r\n\r\nSystem.<em>out<\/em>.println(\"values of Navigable Map 4: \"+nm4);\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>values of Navigable Map 1: {98=Core, 100=I, 101=Love, 103=Java}\r\n\r\nvalues of Navigable Map 2: {100=I, 101=Love}\r\n\r\nvalues of Navigable Map 3: {98=Core, 100=I, 101=Love}\r\n\r\nvalues of Navigable Map 4: {100=I, 101=Love, 103=Java}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>33. SortedMap subMap(Object fromKey, Object toKey)<\/strong><\/span><\/p>\n<p>This method returns a group of this map whose keys range from fromKey(including its value), to toKey(excluding its value), as shown in the following program.<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\nSortedMap&lt;Integer, String&gt; sm = new TreeMap&lt;Integer, String&gt;();\r\n\r\ntm.put(98,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\nsm=tm.subMap(98,103);\r\n\r\nSystem.<em>out<\/em>.println(\"Sub Map obtained :\" +sm);\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Sub Map obtained :{98=Core, 100=I, 101=Love}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>34.\u00a0SortedMap tailMap(Object fromKey)<\/strong><\/span><\/p>\n<p>This method returns a group of entries of this map whose keys are greater than or equal to fromKey, as shown in the following program.<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\nSortedMap&lt;Integer, String&gt; sm = new TreeMap&lt;Integer, String&gt;();\r\n\r\ntm.put(98,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\nsm=tm.tailMap(101);\r\n\r\nSystem.<em>out<\/em>.println(\"Tail map values: \"+sm);\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Tail map values: {101=Love, 103=Java}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>35.\u00a0NavigableMap \u00a0tailMap(Object fromKey, boolean inclusive)<\/strong><\/span><\/p>\n<p>This method returns a group of entries of this map whose keys are greater than or equal to (or equal to, if inclusive is true) fromKey, \u00a0as shown in the following program.<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\nSortedMap&lt;Integer, String&gt; sm1 = new TreeMap&lt;Integer, String&gt;();\r\n\r\nSortedMap&lt;Integer, String&gt; sm2 = new TreeMap&lt;Integer, String&gt;();\r\n\r\ntm.put(98,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\nsm1=tm.tailMap(100, true);\r\n\r\nsm2=tm.tailMap(100, false);\r\n\r\nSystem.<em>out<\/em>.println(\"Tail map values of First Map: \"+sm1);\r\n\r\nSystem.<em>out<\/em>.println(\"Tail map values of Second Map: \"+sm2);\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Tail map values of First Map: {100=I, 101=Love, 103=Java}\r\n\r\nTail map values of Second Map: {101=Love, 103=Java}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>36.\u00a0Collection values()<\/strong><\/span><\/p>\n<p>This method returns a collection of all the entries in the TreeMap, as shown in the following program<\/p>\n<pre>import java.util.*;\r\n\r\npublic class TreeMapDemo{\r\n\r\npublic static void main(String args[]){\r\n\r\nTreeMap&lt;Integer,String&gt; tm=new TreeMap&lt;Integer,String&gt;();\r\n\r\ntm.put(102,\"Core\");\r\n\r\ntm.put(100,\"I\");\r\n\r\ntm.put(103,\"Java\");\r\n\r\ntm.put(101,\"Love\");\r\n\r\nCollection coll=tm.values();\r\n\r\nSystem.<em>out<\/em>.println(\"Value of the collection: \"+coll);\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<pre>Value of the collection: [I, Love, Core, Java]\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>TreeMap store values based on \u00a0key value pairs. This pair is often called as Entry.\u00a0It \u00a0stores only unique elements\u00a0i.e.\u00a0duplicate values are not allowed and it cannot store key as null but can store null values. Mostly it is similar to HashMap Class and key difference is,\u00a0it maintains an increasing order of the values based on &hellip; <a href=\"https:\/\/abhiandroid.com\/java\/treemap-methods.html\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">TreeMap Methods Tutorial With Examples in JAVA<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,77],"tags":[],"class_list":["post-1026","post","type-post","status-publish","format-standard","hentry","category-archieve","category-java-collections"],"psp_head":"<title>TreeMap Methods Tutorial With Examples in JAVA \u2013 Abhi Android<\/title>\r\n<meta name=\"description\" content=\"TreeMap store values based on key value pairs. This pair is often called as Entry. It stores only unique elements i.e. duplicate values are not allowed and it cannot store key as null but can store null values. Mostly it is similar to HashMap Class and key difference is, it maintains an increasing order of the values based on the keys.\" \/>\r\n<meta name=\"robots\" content=\"index,follow\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/abhiandroid.com\/java\/treemap-methods.html\" \/>\r\n","_links":{"self":[{"href":"https:\/\/abhiandroid.com\/java\/wp-json\/wp\/v2\/posts\/1026","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/abhiandroid.com\/java\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/abhiandroid.com\/java\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/abhiandroid.com\/java\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/abhiandroid.com\/java\/wp-json\/wp\/v2\/comments?post=1026"}],"version-history":[{"count":1,"href":"https:\/\/abhiandroid.com\/java\/wp-json\/wp\/v2\/posts\/1026\/revisions"}],"predecessor-version":[{"id":1458,"href":"https:\/\/abhiandroid.com\/java\/wp-json\/wp\/v2\/posts\/1026\/revisions\/1458"}],"wp:attachment":[{"href":"https:\/\/abhiandroid.com\/java\/wp-json\/wp\/v2\/media?parent=1026"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/abhiandroid.com\/java\/wp-json\/wp\/v2\/categories?post=1026"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/abhiandroid.com\/java\/wp-json\/wp\/v2\/tags?post=1026"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}