InetSocketAddress toString Example

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


InetSocketAddress class toString example. public String toString() Constructs a string representation of this InetSocketAddress. This String is constructed by calling toString() on the InetAddress and concatenating the port number (with a colon). If the address is unresolved then the part before the colon will only contain the hostname.

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

import java.net.*;

public class ToString {

    public static void main(String args[]) throws Exception {
        
        //Get local host.
        InetAddress inetAddress = InetAddress.getLocalHost();

        InetSocketAddress inetSocketAddress = new InetSocketAddress(inetAddress, 1313);
        
        System.out.println(inetSocketAddress.toString());
    }
}

Output
komal-desktop/127.0.1.1:1313

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

HOME | COPYRIGHT | CONTACT US