Java API Tutorial - Java InetAddress.equals(Object obj)








Syntax

InetAddress.equals(Object obj) has the following syntax.

public boolean equals(Object obj)

Example

In the following code shows how to use InetAddress.equals(Object obj) method.

import java.net.InetAddress;

public class Main {
  public static void main(String[] argv) throws Exception {
    byte[] ipAddr = new byte[] { 127, 0, 0, 1 };
    InetAddress addr = InetAddress.getByAddress("Localhost",ipAddr);
    System.out.println(addr.equals(InetAddress.getByAddress(ipAddr)));
  }
}

The code above generates the following result.