Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Loop in NavigableMap in Java

Tags:

java

Is there any way to loop in NavigableMap in Java? I want to access all of item in NavigableMap.

like image 406
Mahdi Avatar asked Mar 17 '12 12:03

Mahdi


People also ask

What is a NavigableMap in Java?

The NavigableMap interface is a member of the Java Collection Framework. It belongs to java. util package and It is an extension of SortedMap which provides convenient navigation methods like lowerKey, floorKey, ceilingKey and higherKey, and along with this popular navigation method.


1 Answers

The same way you would loop any collection, with an iterator or for-each loop.

NavigableMap<K, V> map = ...

for(K key: map.keySet()) // iterate keys.

for(V value: map.values()) // iterate values.

for(Entry<K, V> entry: map.entrySet()) // iterate key/value entries.
like image 164
Peter Lawrey Avatar answered Oct 04 '22 20:10

Peter Lawrey