My Host entry as follow :
10.106.1.188 myhost
192.168.0.156 myhost
192.168.0.160 myhost
192.168.0.150 myhost
10.106.1.121 myhost
10.106.1.110 myhost
I use following code for get all IP Address from host entry
InetAddress[] addresses = InetAddress.getAllByName("myhost");
for( InetAddress address : addresses) {
System.out.println(address);
}
Problem is above code does not manage Ip Address order.
When Running above program on Windows 7 it works fine but on linux machine it does not manage order
I would suggest Use Comparator which should sort the IP address for you. other wise you will get platform dependent results. Here is one example http://thilosdevblog.wordpress.com/2010/09/15/sorting-ip-addresses-in-java/ This example keeps Ordering intact.