Iam getting exception in line 18, for the below program,
Exception in thread "main" java.lang.IndexOutOfBoundsException: toIndex = 1600
at java.util.SubList.<init>(Unknown Source)
at java.util.RandomAccessSubList.<init>(Unknown Source)
at java.util.AbstractList.subList(Unknown Source)
[1200, 1350, 1490, 1550, 1845, 2010, 2100]
why the exception? the same things work out when used in HashSet. i.e)subset(1200,1600) is working using TreeSet.
scjp 1.6 91%, preparing for scmad
"Time to get MAD now.. we will get even later"....by someone unknown
posted 10 years ago
The code for the TreeSet version looks excellent.
The difference is that subSet() takes two Objects as its arguments (that is, two objects actually IN the set), and subList() takes the int value of the indeces. It looks like you've got a good handle on the syntax as well. Looks good!
Evacuate the building! Here, take this tiny ad with you: