日期:2014-05-19 浏览次数:20773 次
public static void main(String[] args) {
String[] array = { "10_Camare_1 20121110 060059.jpg",
"11_Camare_1 20121110 070059.jpg",
"12_Camare_1 20121110 080059.jpg",
"13_Camare_1 20121110 090059.jpg",
"14_Camare_1 20121110 100102.jpg",
"15_Camare_1 20121110 110059.jpg",
"16_大门 20121110 120059.jpg",
"17_站区 20121110 130059.jpg",
"5_Camare_1 20121110 010059.jpg",
"6_Camare_1 20121110 020059.jpg",
"7_Camare_1 20121110 030059.jpg",
"8_Camare_1 20121110 040059.jpg",
"9_Camare_1 20121110 050059.jpg" };
final Pattern pattern = Pattern.compile("^\\d+");
Arrays.sort(array, new Comparator<String>() {
@Override
public int compare(String str1, String str2) {
int index1 = 0, index2 = 0;
Matcher matcher = pattern.matcher(str1);
if(matcher.find())
index1 = Integer.parseInt(matcher.group());
matcher.reset(str2);
if(matcher.find())
index2 = Integer.parseInt(matcher.group());
return index1 - index2;
}
});
for(String str : array){
System.out.println(str);
}
}