wood burning stoves*
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
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.
It is sorta covered in the JavaRanch Style Guide.
subject: Doubt on subMap() in NavigableMap
Similar Threads
K&B-6-pg-591 - Backed Collections - exam watch
using TreeSet TreeMap with Strings And Integers Problem
Collection problem
Important detail concerning "backed collection" methods for TreeSet and TreeMap
Problem using pollLastEntry() method from TreeMap