User:Alexsmail/Computer programming/How Objects should be correctly compared in Java

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Introduction[edit | edit source]

See appendix A for formal definition.

Method along consideration[edit | edit source]

equals()[edit | edit source]

Object hirerachy and its state (getClass() or instanceof ?). Immutable object. Object.equals()

hashCode()[edit | edit source]

Object.hashCode()

Natural order - compareTo()[edit | edit source]

Comparable#compareTo()

compareTo()[edit | edit source]

Comparable#compareTo()

Comparable#equals()

Map (Hashtable)[edit | edit source]

Combination consideration[edit | edit source]

equals() and hashCode()[edit | edit source]

Object.hashCode()

equals() and compareTo()[edit | edit source]

equals() and compareTo() and hashCode()[edit | edit source]

HashMap, equals() and compareTo()[edit | edit source]

TreeMap, equals() and compareTo()[edit | edit source]

Maps, Hashtable and Set and Arrays[edit | edit source]

HashMap's and Set's key[edit | edit source]

Immutable. keys are Uniformly distributed.

TreeMap vs HashMap[edit | edit source]

Sort[edit | edit source]

QuickSort MergeSort Stable sort Comparator TreeMap


Miscellaneous[edit | edit source]

signum function[edit | edit source]

Sorting with Comparator[edit | edit source]

Arrays.sort()


Appendix B[edit | edit source]

Mathematic background[edit | edit source]

Set Order pair Relation Relation over Set Two-place relation function function in Java Partial Order Full order Equivalence relation Equivalence class