cs.jdoner.me ยท flagship
CompareTo Methods
{{ className }}
this
{{ primType }}
{{ primName }}
{{ thisPrim }}
{{ refType }}
{{ refName }}
{{ thisRef }}
{{ className }}
other
{{ primType }}
{{ primName }}
{{ otherPrim }}
{{ refType }}
{{ refName }}
{{ otherRef }}
{{ rungBadge }}
{{ rungTitle }}
{{ rungPrompt }}
{{ l.n }}
{{ l.text }}
{{ typingN }}
!
{{ hintMsg }}
Predict the output
Given these two objects, what does this multi-key compareTo return?
public int compareTo({{ className }} other) {
int cmp = Integer.compare(this.{{ primName }}, other.{{ primName }});
if (cmp != 0) return cmp;
return this.{{ refName }}.compareTo(other.{{ refName }});
}
{{ pFeedbackText }}