public class CharPair { char[] c; public CharPair(char char1, char char2) { c = new char[2]; c[0] = char1; c[1] = char2; } public String toString() { return new String(c); } public boolean equals(Object anObject) { if (anObject != null && anObject instanceof CharPair) { CharPair aCharPair = (CharPair)anObject; return c[0] == aCharPair.c[0] && c[1] == aCharPair.c[1]; } else return false; } public int hashCode() { // This hash function uses the OR ("|") and LEFT SHIFT ("<<") bit operators. // The Java specification states that a "char" is an unsigned 16-bit value // that represents a Unicode character. We can therefore take advantage of // all the bits available by shifting one of the chars left 16 bits (which is the // same as multiplying by 65536) and performing a bitwise OR on the other char // (which is the same as adding it). return Character.getNumericValue(c[0]) | (Character.getNumericValue(c[1]) << 16); } }