About Question enthuware.ocpjp.v7.2.1471 :
Moderator: admin
About Question enthuware.ocpjp.v7.2.1471 :
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?
- 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?
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1471 :
It is difficult to indentify issues with IDE. Please use command line compilation to see what is the exact error.
-
- Posts: 27
- Joined: Sat Aug 31, 2013 5:38 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1471 :
Are you using the jdk7 ?
-
- Posts: 14
- Joined: Sun Dec 06, 2015 2:15 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1471 :
I understand the solution, but why is this:
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
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)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."
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
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1471 :
Correct.codecodecode67 wrote:I understand the solution, but why is this:
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)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."
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
-
- Posts: 62
- Joined: Fri Aug 07, 2015 2:16 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1471 :
How to understand "range" correctly.
What if I have the following code:
What defines "range" here?
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;
}
}
}
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1471 :
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.
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.
Who is online
Users browsing this forum: Bing [Bot] and 3 guests