This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
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 Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt on subMap() in NavigableMap" Watch "Doubt on subMap() in NavigableMap" New topic

Doubt on subMap() in NavigableMap

Kir Swa

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.
I agree. Here's the link:
subject: Doubt on subMap() in NavigableMap