Skip to content

Instantly share code, notes, and snippets.

@keehyun2
Created January 28, 2018 04:10
Show Gist options
  • Save keehyun2/50b9b0f04d31d000ac99150b22a66414 to your computer and use it in GitHub Desktop.
Save keehyun2/50b9b0f04d31d000ac99150b22a66414 to your computer and use it in GitHub Desktop.
CustomString
class CustomString implements Comparable<CustomString> {
public String str;
public CustomString(String str) {
this.str = str;
}
public int compareTo(CustomString cs) {
int leng1 = this.str.length();
int leng2 = cs.str.length();
if (leng1 < leng2) return -1;
if (leng1 > leng2) return 1;
return this.str.compareTo(cs.str); // 길이가 같은 경우만 compareTo 사용함
}
}
public static void main(String[] args) throws NumberFormatException, IOException {
PriorityQueue<CustomString> pq = new PriorityQueue<CustomString>();
pq.add(new CustomString("axcdcc"));
pq.add(new CustomString("33"));
pq.add(new CustomString("zsdc"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment