SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
t.put(d1,"AIKO");
t.put(d2,"CLOVER");
t.put(d3,"CLOVER");
SCJP 6
Originally posted by Punit Singh:
When this line called, TreeMap will call
1) d1.hashCode()==d2.hashCode(), this will return true as 7==7 is true, so it will call equals().
2) d1.equals(d2) will be called, this will return false as "AIKO"!="CLOVER".
equals() returns false so it will add d2 in the TreeMap
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
SCJP 6
Originally posted by Punit Singh:
hashCode() will not be used, may be TreeMap is not a collection that uses Hashing for storage purpose.
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
// Red-black mechanics
private static final boolean RED = false;
private static final boolean BLACK = true;
/**
* Node in the Tree. Doubles as a means to pass key-value pairs back to
* user (see Map.Entry).
*/
static final class Entry<K,V> implements Map.Entry<K,V> {
K key;
V value;
Entry<K,V> left = null;
Entry<K,V> right = null;
Entry<K,V> parent;
boolean color = BLACK;
SCJP 6
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
SCJP 6
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
All code in my posts, unless a source is explicitly mentioned, is my own.
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|