package collection;
import java.util.Arrays;
import java.util.TreeSet;
public class Demo6 {
/**
* @ip地址排序
*/
public static void main(String[] args) {
String str = "192.68.1.254 102.49.23.013 10.10.10.10 2.2.2.2 8.109.90.30";
str = str.replaceAll("(\\d+)","00$1");
//sop(str);
str = str.replaceAll("0*(\\d{3})","$1");
//sop(str);
String[] s = str.split(" +");
//第一种排序方式
//Arrays.sort(s);
//第二种排序方式
TreeSet<String> ts = new TreeSet<String>();
for(String x:s)
ts.add(x);
for(String x:ts)
sop(x.replaceAll("0*(\\d+)","$1"));
}
public static void sop(Object obj){
System.out.println(obj);
}
}
原文链接:https://www.f2er.com/regex/360208.html