import java.util.Arrays;
public class Test2 {
public static String[] strs={"anna","aec","bc","abc"};
public static void main(String args[])
{
sort();
}
public static void sort()
{
Arrays.sort(strs);
for(String str:strs)
{
System.out.println(str);
}
}
}
给你个例子啊。你看过之后就明白了。
import java.util.Arrays;
public class EnglishSort {
public static void main(String[] args) {
String str="IndexWriter writer = new IndexWriter(ramDir, analyzer)";
StringBuffer buff=new StringBuffer(str);
char[] arr=str.toCharArray();
Arrays.sort(arr);
for(int i=0,j=0;i
while(true){
if(String.valueOf(buff.charAt(j)).matches("[a-zA-Z]")){
buff.setCharAt(j, arr[i]);
j++;
break;
}
j++;
}
}
}
System.out.println(buff.toString());
}
}
用到把数值转换为ASC码来进行比较。还能同时比较大小写 。明白吧
#include