Skip to content

Instantly share code, notes, and snippets.

@jononon
Created December 15, 2015 03:28
Show Gist options
  • Select an option

  • Save jononon/1f794bfd008483ae4f3d to your computer and use it in GitHub Desktop.

Select an option

Save jononon/1f794bfd008483ae4f3d to your computer and use it in GitHub Desktop.
public class Name implements Comparable {
private String first, last;
public Name (String firstName, String lastName) {
first = firstName;
last = lastName;
}
public int compareTo(Object obj) {
Name other = (Name) obj;
if(other.toString().equals(this.toString()))
return 0;
else if (other.last == this.last)
return this.first.compareTo(other.first);
else
return this.last.compareTo(other.last);
}
public String toString() {
return first+" "+last;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment