wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt on subMap() in NavigableMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt on subMap() in NavigableMap" Watch "Doubt on subMap() in NavigableMap" New topic
Author

Doubt on subMap() in NavigableMap

Kir Swa
Greenhorn

Joined: May 03, 2012
Posts: 9
Source of the code: ExamLab


Line 1:NavigableMap ns=nv.subMap(0, true, 6, true);
Line 2:NavigableMap ns=nv.subMap(1, true, 4, true).subMap(0, true, 3, true);

Both method arguments are out of bounds, but Why iam getting Exception when inserting Line2 but not Line1?

And the Similar problem with subSet()

Thanks in advance

saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

code tag please.


Tell the difficulties that i am difficult.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Kir Swa wrote:
NavigableMap ns=nv.subMap(1, true, 4, true).subMap(0, true, 3, true);


first sunMap invocation makes fromKey index to 1 there is no 0 index and now the second subMap access the 0 from key index which is not available, hence exception.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Doubt on subMap() in NavigableMap