I need to sort strings containing numbers
Eg :
input : {"1","12","12","2","ABC","a"}
Expected output: 1 2 12 a ABC
My output :1 2 12 12 a ABC
I am not able to remove duplicate. can anyone help me with this ?
Below is the code I used for sorting
public static String[] Sort(String[] list) {
Comparator<String> comp = new Comparator<String>() {
public int compare(String str1, String str2) {
try {
int num1 = Integer.parseInt(str1);
int num2 = Integer.parseInt(str2);
return Integer.compare(num1, num2);
}
catch (NumberFormatException e) {
return str1.compareTo(str2);
}
}
};
Arrays.sort(list, comp);
return list;
}
Thanks in Advance