Create IP address by Host Name in Java
Description
The following code shows how to create IP address by Host Name.
Example
/*from w ww .ja v a2 s. c om*/
import java.net.InetAddress;
public class Main {
public static void main(String[] args) {
try {
InetAddress ia = InetAddress.getByName("google.com");
System.out.println(ia.getHostAddress());
System.out.println(ia.getHostName());
} catch (Exception ex) {
System.err.println(ex);
}
}
}
The code above generates the following result.