Page 1 of 1
About Question enthuware.ocpjp.v7.2.1471 :
Posted: Tue Mar 12, 2013 3:36 am
by ETS User
In Eclipse this error: Multiple markers at this line
- The type TreeSet is not generic; it cannot be parameterized with arguments
<Integer>
- The type TreeSet is not generic; it cannot be parameterized with arguments
<Integer>
Why?
Re: About Question enthuware.ocpjp.v7.2.1471 :
Posted: Tue Mar 12, 2013 10:13 am
by admin
It is difficult to indentify issues with IDE. Please use command line compilation to see what is the exact error.
Re: About Question enthuware.ocpjp.v7.2.1471 :
Posted: Mon Sep 02, 2013 3:08 pm
by sinapse
Are you using the jdk7 ?
Re: About Question enthuware.ocpjp.v7.2.1471 :
Posted: Fri May 20, 2016 8:23 pm
by codecodecode67
I understand the solution, but why is this:
Further, since the subset is created using a range (fromElement to toElement), the element that you are inserting must fall within that range. Otherwise an IllegalArgumentException is thrown with a message "key out of range."
the case? Why must it be within that range, why does it matter that the subset is created using a range? How is a subset created from a range different from a regular treeset? (I'm trying to rephrase my question a couple of times to make it more clear what I don't get)
Edit: Does the insertion have to be within the range of the subset because the subset is backed by the actual set, so if it's outside of the range of the subset, there won't be a valid place to put it in the real subset?
Does this mean that this is also valid in the same way for NavigableMap implementations and its subMap(...) methods?
Thanks
Re: About Question enthuware.ocpjp.v7.2.1471 :
Posted: Fri May 20, 2016 9:56 pm
by admin
codecodecode67 wrote:I understand the solution, but why is this:
Further, since the subset is created using a range (fromElement to toElement), the element that you are inserting must fall within that range. Otherwise an IllegalArgumentException is thrown with a message "key out of range."
the case? Why must it be within that range, why does it matter that the subset is created using a range? How is a subset created from a range different from a regular treeset? (I'm trying to rephrase my question a couple of times to make it more clear what I don't get)
Edit: Does the insertion have to be within the range of the subset because the subset is backed by the actual set, so if it's outside of the range of the subset, there won't be a valid place to put it in the real subset?
Correct.
Does this mean that this is also valid in the same way for NavigableMap implementations and its subMap(...) methods?
Thanks
Correct.
Re: About Question enthuware.ocpjp.v7.2.1471 :
Posted: Tue Dec 13, 2016 12:13 pm
by sir_Anduin@yahoo.de
How to understand "range" correctly.
What if I have the following code:
What defines "range" here?
Code: Select all
public class Main2 {
public static void main(String[] args) {
TreeSet<Animal> s = new TreeSet<Animal>();
TreeSet<Animal> subs = new TreeSet<Animal>();
Animal e = new Animal();
s.add(e);
s.add(new Animal());
s.add(new Animal());
Animal e1 = new Animal();
s.add(e1);
subs = (TreeSet) s.subSet(e, true, e1, true);
subs.add(new Animal());
System.out.println(s + " " + subs);
}
class Animal implements Comparable<Animal> {
@Override
public int compareTo(Animal o) {
return 0;
}
}
}
Re: About Question enthuware.ocpjp.v7.2.1471 :
Posted: Tue Dec 13, 2016 1:43 pm
by admin
s points to a TreeSet. A TreeSet is a sorted set, which means its elements are stored in a sorted fashion. For example, if you store numbers 1 to 9 in a TreeSet, they will be kept in sorted order i.e. from 1 to 9. Now, if you create a subset using this set using subSet(3, true, 6, true); the range of the subset is 3 to 6. You cannot insert number 2 or 7 in this subset because they out of that range.
You should go through the JavaDoc API of this method for further details and try out a few examples to get a better understanding.
HTH,
Paul.