对一个String类型的字符串进行排序
import java.util.Arrays;
import java.util.Comparator;
public class Temp2
{
public static void main(String args[])
{
String str2 = "33 35 43 21 12 10 5 67 65";
String[] str = str2.split(" ");
Arrays.sort(str, new CustomComparator2());
for(Object s: str)
{
System.out.println(s);
}
}
}
class CustomComparator2 implements Comparator<String>
{
public int compare(String str1, String str2)
{
int name1 = Integer.parseInt(str1);
int name2 = Integer.parseInt(str2);
return name1 - name2;
}
} |