Created
March 15, 2013 19:58
-
-
Save Ray1988/5172675 to your computer and use it in GitHub Desktop.
sorted a string array base on anagram.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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