Java InetAddress .getAllByName (String host)

Syntax

InetAddress.getAllByName(String host) has the following syntax.

public static InetAddress [] getAllByName(String host)     throws UnknownHostException

Example

In the following code shows how to use InetAddress.getAllByName(String host) method.


import java.net.*;
/*from   w w  w. j a v a 2s.  com*/
public class Main {

  public static void main (String[] args) {

    try {
      InetAddress[] addresses = InetAddress.getAllByName("www.google.com");
      for (int i = 0; i < addresses.length; i++) {
        System.out.println(addresses[i]);
      }
    }
    catch (UnknownHostException e) {
      System.out.println("Could not find www.apple.com");
    }

  }

}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.net »




CookieManager
CookiePolicy
CookieStore
DatagramPacket
DatagramSocket
HttpCookie
HttpURLConnection
InetAddress
JarURLConnection
MulticastSocket
ServerSocket
Socket
SocketAddress
URI
URL
URLConnection
URLDecoder
URLEncoder