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.
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!