import java.util.*;
class Regtest
{
public static void main(String[] args)
{
ipsort();
}
//给ip排序
public static void ipsort()
{
String ip="129.3.4.5 21.3.4.6 3.4.3.2 1.2.5.7 5.44.45.6";
ip=ip.replaceAll("(\\d+)","00$1");//替换序列所有数字保证每位数字最低位为三位
System.out.println(ip);
ip=ip.replaceAll("0*(\\d{3})","$1");//替换每一位数字的位数大于三位的,是数组中每个数字都是三位数
System.out.println(ip);
String[] arr=ip.split(" +");
TreeSet<String> set=new TreeSet<String>();
for (String s:arr )
{
set.add(s);
}
for (String s:set )
{
System.out.println(s.replaceAll("0*(\\d+)","$1"));
}
}
}
|