![]() |
VOOZH | about |
The get() method of the TreeMap class in Java is used to retrieve or fetch the value mapped by a particular key mentioned in the parameter. If the key does not exist in the map, the method returns null.
treeMap.get(Object key)
Example 1: In this example, we are going to create a TreeMap with integer keys and string values, and then we will fetch the values for specific keys using the get() method.
Initial mapping: {10=Geeks, 15=4, 20=Geeks, 25=Welcomes, 30=You}
The Value is: Welcomes
The Value is: Geeks
Example 2: In this example, we are going to create a TreeMap with string keys and integer values.
Initial Mapping: {4=15, Geeks=20, Welcomes=25, You=30}
The Value is: 20
The Value is: 30
Important Points: