Java API Tutorial - 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  va 2s  .  co m
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.