我想对包含数字和字符的字符串进行排序
I want sorting on string which contains numbers and characters
我想对包含数字和字符的字符串进行排序。
首先,它应该对数字进行排序,然后对字符串进行排序。
输入:
string[] alphanumeric = new string[]
{
"0012", "0000","1200", "0002", "9700","AB10", "0IWZ", "XZYA", "0003", "ABCD"
};
预期输出:
0000
0002
0003
0012
0IWZ
1200
9700
AB10
ABCD
ZYYA
你应该使用这样的Arrays.sort方法:
private void print(){
String[] alphanumeric = new String[]
{
"0012", "0000","1200", "0002", "9700","AB10", "0IWZ", "XZYA", "0003", "ABCD"
};
Arrays.sort(alphanumeric);
System.out.println(Arrays.toString(alphanumeric));
/* output: [0000, 0002, 0003, 0012, 0IWZ, 1200, 9700, AB10, ABCD, XZYA] */
}
我想对包含数字和字符的字符串进行排序。 首先,它应该对数字进行排序,然后对字符串进行排序。 输入:
string[] alphanumeric = new string[]
{
"0012", "0000","1200", "0002", "9700","AB10", "0IWZ", "XZYA", "0003", "ABCD"
};
预期输出:
0000
0002
0003
0012
0IWZ
1200
9700
AB10
ABCD
ZYYA
你应该使用这样的Arrays.sort方法:
private void print(){
String[] alphanumeric = new String[]
{
"0012", "0000","1200", "0002", "9700","AB10", "0IWZ", "XZYA", "0003", "ABCD"
};
Arrays.sort(alphanumeric);
System.out.println(Arrays.toString(alphanumeric));
/* output: [0000, 0002, 0003, 0012, 0IWZ, 1200, 9700, AB10, ABCD, XZYA] */
}