我调用socket.getInetAddress()方法获得了IP地址。
再调用toString()转换下,是不是就成这样的格式了呢 /xxx.xxx.xxx.xxx 比如 /127.0.0.1是这样吗????转换后如果想转回来有什么办法吗?没有现成的方法,我也不会写。或者比如把/127.0.0.1这个字符串转换成127.0.0.1,也行,谁有办法????
再调用toString()转换下,是不是就成这样的格式了呢 /xxx.xxx.xxx.xxx 比如 /127.0.0.1是这样吗????转换后如果想转回来有什么办法吗?没有现成的方法,我也不会写。或者比如把/127.0.0.1这个字符串转换成127.0.0.1,也行,谁有办法????
public static void main(String[] args)throws Exception{
//下面不就是由String 转为ip吗?
InetAddress ip=InetAddress.getByName("127.0.0.1");
String ipStr=ip.toString();
System.out.println(ipStr);
//再转一下:
InetAddress ip2=InetAddress.getByName(ipStr.substring(1));
System.out.println(ip2);
}
}
int i;
int j;
int z;
//所谓的优化
long time5 = System.nanoTime();
for(i=0; i<10; i++) {
for(j=0; j<100; j++) {
for(z=0; z<1000; z++) {
}
}
}
long time6 = System.nanoTime();
System.out.println(time6 - time5);
//原题
time5 = System.nanoTime();
for(i=0; i<1000; i++) {
for(j=0; j<100; j++) {
for(z=0; z<10; z++) {
}
}
}
time6 = System.nanoTime();
System.out.println(time6 - time5);
}
}
//C:\>java Test
//2652572
//2125130这样怎么解释呢,经过多次测试,在同等次数的循环中,放在最上面的循环(离Main方法最近)
时间总是最多的。
InetAddress ip=InetAddress.getByName("127.0.0.1");
System.out.print(ip.toString().substring(1));