- public static void main(String[] args) throws Exception {
- ArrayList<String> list =new ArrayList<>();
- list.add("61.54.231.245");
- list.add("61.54.231.9");
- list.add("61.54.231.246");
- list.add("61.54.231.48");
- list.add("61.53.231.249");
- Collections.sort(list, new Comparator<String>() {
- @Override
- public int compare(String o1, String o2) {
- String[] a1 = o1.split("\\.");
- String[] a2 = o2.split("\\.");
- int i = Integer.parseInt(a1[0])-Integer.parseInt(a2[0]);
- int i2= i==0?Integer.parseInt(a1[1])-Integer.parseInt(a2[1]):i;
- int i3= i2==0?Integer.parseInt(a1[2])-Integer.parseInt(a2[2]):i2;
- return i3==0?Integer.parseInt(a1[3])-Integer.parseInt(a2[3]):i3;
- }
- });
- System.out.println(list);
- PrintStream ps= new PrintStream(new FileOutputStream("times.txt"));
- for(String s:list){
- ps.println(s);
- }
- ps.close();
- }
- }
复制代码 |
|