InterfaceAddress toString Example

InterfaceAddress class toString example. This example shows you how to use toString method.


InterfaceAddress class toString example. public String toString() Converts this Interface address to a String. The string returned is of the form: InetAddress / prefix length [ broadcast address ].

Here is the code
/*
 * @ # HashCode.java
 * A class repersenting use to HashCode method 
 * of InterfaceAddress class in java.net package
 * version 23 June 2008
 * author Rose India 
 */

import java.net.*;
import java.util.*;

public class ToString {

    public static void main(String args[]) throws Exception {
        NetworkInterface networkInterface =
                NetworkInterface.getByName("eth0");

        List<InterfaceAddress> address =
                networkInterface.getInterfaceAddresses();

        for (InterfaceAddress interfaceAddress : address) {
            System.out.println("InterfaceAddress " + interfaceAddress.toString());
        }
    }
}

Output
InterfaceAddress /fe80:0:0:0:219:d1ff:fe61:be38%2/64 [null]
InterfaceAddress /192.168.10.222/24 [/192.168.10.255]

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US