Skip to content

Instantly share code, notes, and snippets.

@Ray1988
Created March 15, 2013 19:58
Show Gist options
  • Save Ray1988/5172675 to your computer and use it in GitHub Desktop.
Save Ray1988/5172675 to your computer and use it in GitHub Desktop.
sorted a string array base on anagram.
public class AnagramComparator implement Comparator<String>{
public String sort(String s){
char[] c= s.toCharArray()
Arrays.sort(c);
return new String(c);
}
public int compare(String s1, String s2){
return sort(s1).compareTo(sort(s2));
}
}
public void anagramSort(String[] sArray){
if(sArray==null) return null;
Arrays.sort(sArray, new AnagramComparator());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment