Android examples for java.net:InetAddress
Format IP address And Port To String
import android.system.OsConstants; import android.system.OsConstants; import java.net.Inet6Address; import java.net.InetAddress; import java.nio.BufferOverflowException; import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; import java.nio.ShortBuffer; public class Main{ public static String addressAndPortToString(InetAddress address, int port) { return String.format((address instanceof Inet6Address) ? "[%s]:%d" : "%s:%d", address.getHostAddress(), port); }/*from w w w.ja v a 2s .com*/ }