Java API Tutorial - Java InetAddress.toString()








Syntax

InetAddress.toString() has the following syntax.

public String toString()

Example

In the following code shows how to use InetAddress.toString() method.

//from  w w w.  ja  va2  s .  c o  m
import java.net.InetAddress;
import java.net.UnknownHostException;

public class Main {

  public static void main(String args[]) {

    try {
      InetAddress inetAddr = InetAddress.getByName("www.java2s.com");
      System.out.println(inetAddr.toString());

    } catch (UnknownHostException ex) {

    }
  }
}

The code above generates the following result.