• 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

java champ....NavigableMap Question

 
Greenhorn
Posts: 29
Hibernate Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


i am getting java.lang.IllegalArgumentException: key out of range at line 16..
any one can please explain me why...
 
Ranch Hand
Posts: 146
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Saikiran,

The method headMap used in the sample code returns a NavigableMap that is linked with your TreeMap (tree) instance.


From JSE 6 Doc API - NavigableMap interface,
the method: NavigableMap<K,V> headMap(K toKey, boolean inclusive)

Returns a view of the portion of this map whose keys are less than (or equal to, if inclusive is true) toKey.
The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa.



Since the returned collection is linked to its source, it must consider the boundaries of this new collection. In this case the boundary is the element that you've used to create your headMap collection ("ee" element).
You can only add elements that are less than "ee" as "dd" or "bb". But never "ff" neither "ee" because you get "ee" was used as exclusively when you set the second argument of headMap to false.

This is your code placed on code tags.



hope this help you
 
saikiran venkata
Greenhorn
Posts: 29
Hibernate Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Adolfo Eloy

thanks for the explanation
 
reply
    Bookmark Topic Watch Topic
  • New Topic