排序前: 25.1.2.23 10.2.23.3 22.21.2.4 10.1.23.3 排序后: 10.1.23.3 10.2.23.3 22.21.2.4 25.1.2.23
字典排序方法。直接存放在数组中,对数组进行排序后输出。
import java.util.*;
public class Main {
public static void main(String[] args) {
String [] strs={"25.1.2.23","10.2.23.3","22.21.2.4","10.1.23.3"};
System.out.println("排序前:"+Arrays.toString(strs));
Arrays.sort(strs);
System.out.println("排序后:"+Arrays.toString(strs));
}
}