SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
1) Why not C is considered as Correct???
2) Why comparable is needed here. Is using comparator wrong?
SCJP 6
Ankit Garg wrote:Well c is wrong as no object will be added to the Set. The first add operation will generate an exception. For elements of a class to be added to a sorted collection like TreeSet, the class must implement Comparable not Comparator. If the class doesn't implement Comparator, then you will have to use a comparator to add elements of that class into the collection but then the code will loke like this
Set < test > s1 = new TreeSet < test > (new test()); //passing the comparator to the constructor
Ankit Garg wrote:The first add operation will generate an exception.
SCJP 6
SCJP 6
Ankit Garg wrote:If the class doesn't implement Comparator, then you will have to use a comparator to add elements of that class into the collection
SCJP 6
Punit Singh wrote:Prav I think you really need JDK, otherwise how many things you will memorize this way.
Prav sharma wrote:RED Lines indicate update.
SCJP 6
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
SCJP 6
Prav wrote:
What are other places where classes need to implement Comparable before addition ?
SCJP 6
Prav sharma wrote:
a) Comparable is needed for classes to implement, who are getting added to TreeSet or TreeMap.
Prav sharma wrote:
b) Need for comparable arises when more than one object is added.
SCJP 6
SCJP 6
SCJP 6
Prav sharma wrote:This thread is showing some different icon and the description is HOT. What does it mean?
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|