• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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
 
Get off me! Here, read this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic