How it works...

In this recipe, we implemented a Task class to store Contact objects in a navigable map. Each contact has a name, which is the ID of the task that creates it, and a phone number, which is a number between 1,000 and 2,000. We concatenated these values as keys for the contacts. Each Task object creates 1,000 contacts; these contacts are stored in the navigable map using the put() method.

If you insert an element with a key that exists in the map, the element associated with that key will be replaced by the new element.

The main() method of the Main class creates 26 Task objects, using the letters between A and Z as IDs. Then, you used some methods to obtain data from the map. The firstEntry() method returns a Map.Entry object with the first element of the map. This method doesn't remove the element from the map. The object contains the key and the element. To obtain the element, you called the getValue() method. You can use the getKey() method to obtain the key of that element.

The lastEntry() method returns a Map.Entry object with the last element of the map. The subMap() method returns the ConcurrentNavigableMap object with part of the elements of the map, in this case, the elements that had keys between A1996 and B1002. You used the pollFirst() method to process the elements of the subMap() method. This method returns and removes the first Map.Entry object of the submap.

The following screenshot shows the output of an execution of the program:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.41.229