Home » treemap

Tag Archives: treemap

Comparable Java Example

In this tutorial, we will discuss Java comparable objects. Java provides the Comparator interface and the Comparable interface, which contains only one method, called compareTo. This method compares two objects, to impose an order between them. Specifically, it returns a negative integer, zero, or a positive integer to indicate that the input object is less than, equal to or greater than the existing ...

Read More »

Java Map Example

In this post, we feature a comprehensive Java Map Example. We will discuss about Maps in Java. A Map is an interface that maps keys to values. The keys are unique and thus, no duplicate keys are allowed. A map can provide three views, which allow the contents of the map to be viewed as a set of keys, collection ...

Read More »

Remove mapping from TreeMap example

This is an example of how to remove mapping from a TreeMap, that is removing a key value pair from a TreeMap. Removing mapping from a TreeMap implies that you should: Create a new TreeMap. Populate the map with elements, with put(K key, V value) API method of TreeMap. Invoke remove(Object o) API method of TreeMap with a key as ...

Read More »

Remove all mappings from TreeMap example

In this example we shall show you how to remove all mappings from a TreeMap, that is removing all key value pairs from the TreeMap. To clear a TreeMap one should perform the following steps: Create a new TreeMap. Populate the map with elements, with put(K key, V value) API method of TreeMap. Invoke clear() API method of TreeMap. The ...

Read More »

TreeMap Iterator example

With this example we are going to demonstrate how to obtain a TreeMap Iterator, that is an iterator over the key value pairs of the TreeMap. The TreeMap API provides methods to get an Iterator. In short, to obtain a TreeMap Iterator you should: Create a new TreeMap. Populate the map with elements, with put(K key, V value) API method ...

Read More »

Obtain tail map from TreeMap example

This is an example of how to obtain a tail map from a TreeMap. The TreeMap API provides methods for this operation. Obtaining a tail map from a TreeMap implies that you should: Create a new TreeMap. Populate the map with elements, with put(K key, V value) API method of TreeMap. Invoke tailMap(Object fromKey) API method of TreeMap. It returns ...

Read More »

Obtain sub Map from TreeMap example

In this example we shall show you how to obtain a sub Map from a TreeMap. The TreeMap API provides methods for this operation. To obtain a sub Map from a TreeMap one should perform the following steps: Create a new TreeMap. Populate the map with elements, with put(K key, V value) API method of TreeMap. Invoke subMap(Object fromKey, Object ...

Read More »

Get size of TreeMap example

With this example we are going to demonstrate how to get the size of a TreeMap, that is the number of key value pairs that the TreeMap contains. In short, to get the size of a TreeMap you should: Create a new TreeMap. Populate the map with elements, with put(K key, V value) API method of TreeMap. Invoke size() API ...

Read More »

Get Set view of TreeMap keys example

This is an example of how to get a Set view of the TreeMap keys. Getting a Set view of the TreeMap keys implies that you should: Create a new TreeMap. Populate the map with elements, with put(K key, V value) API method of TreeMap. Invoke keySet() API method of TreeMap. The method returns a Set of all the keys ...

Read More »

Obtain lowest and highest keys from TreeMap example

In this example we shall show you how to obtain the lowest and highest keys from a TreeMap. The TreeMap API provides methods for these operations. To obtain the lowest and highest keys from a TreeMap one should perform the following steps: Create a new TreeMap. Populate the map with elements, with put(K key, V value) API method of TreeMap. ...

Read More »