• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What is the Use of NavigableMap and NavigableSet?

 
Praveen mourya Kumar
Greenhorn
Posts: 16
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is regarding NavigableMap and NavigableSet : I am not able to find the use of them. In K&B, it is not given clearly how they are useful .
Please somebody help me.
 
Ryan Beckett
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I remember k&B doing examples using a TreeSet.

A NavigableSet may be accessed and traversed in either ascending or descending order. The descendingSet method returns a view of the set with the senses of all relational and directional methods inverted. The performance of ascending operations and views is likely to be faster than that of descending ones. This interface additionally defines methods pollFirst and pollLast that return and remove the lowest and highest element, if one exists, else returning null. Methods subSet, headSet, and tailSet differ from the like-named SortedSet methods in accepting additional arguments describing whether lower and upper bounds are inclusive versus exclusive. Subsets of any NavigableSet must implement the NavigableSet interface.



NavigableSet
 
Himalay Majumdar
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NavigableMap and NavigableSet provide various new methods to search thru TreeMap and TreeSet.

Consider this.



Let say you want to find the first number after 15.

To do this before NavigableXXX it was a two step process, which also needed to create a temporary map

TreeSet<Integer> subset = new TreeSet<Integer>();
subset = (TreeSet)num.tailSet(1600);
System.out.println(subset.first())

You can do the same thing in just one line using higher()..coz TreeSet implements NavigableSet

System.out.println(times.higher());

Just like higher() there are some more useful methods. Its a kew feature.
All the above is taken from K&B.
 
Praveen mourya Kumar
Greenhorn
Posts: 16
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ryan Beckett and Himalay Majumdar for your immense help.
 
reply
    Bookmark Topic Watch Topic
  • New Topic