Java Utililty Methods IP Address to String

List of utility methods to do IP Address to String

Description

The list of methods to do IP Address to String are organized into topic(s).

Method

StringconvertIpToString(byte[] ip)
convert Ip To String
sb.delete(0, sb.length());
for (int i = 0; i < ip.length; i++) {
    sb.append(ip[i] & 0xFF).append('.');
sb.deleteCharAt(sb.length() - 1);
return sb.toString();
StringinputStreamContent(InputStream is)
input Stream Content
StringBuilder content = new StringBuilder("");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
char[] buffer = new char[4096];
int charsRead;
try {
    while ((charsRead = bufferedReader.read(buffer)) > 0) {
        content.append(buffer, 0, charsRead);
} catch (IOException e) {
    e.printStackTrace();
    throw e;
} finally {
    bufferedReader.close();
return content.toString();
Stringip2string(byte[] ip)
Converts the given bytes of an IP to a string representation.
if (ip == null) {
    throw new NullPointerException("Ip is null!");
assert ip.length == 4;
return (ip[0] & 0xff) + "." + (ip[1] & 0xff) + '.' + (ip[2] & 0xff) + '.' + (ip[3] & 0xff);
Stringip2string(byte[] ips)
ipstring
int i = 0;
String ipstr = "";
for (i = 0; i < ips.length - 1; i++)
    ipstr += (ips[i] & 0x00ff) + ".";
ipstr += ips[i] & 0x00ff;
return ipstr;
Stringip2String(int ip)
ip String
return String.format("%d.%d.%d.%d", ip & 0xff, (ip >> 8) & 0xff, (ip >> 16) & 0xff, (ip >> 24) & 0xff);
StringipToIPv4Str(byte[] ip)
ip To I Pv Str
if (ip.length != 4) {
    return null;
return new StringBuilder().append(ip[0] & 0xFF).append(".").append(ip[1] & 0xFF).append(".")
        .append(ip[2] & 0xFF).append(".").append(ip[3] & 0xFF).toString();
StringipToString(final byte[] address)
Convert specified array of bytes into an ip-string.
final StringBuffer sb = new StringBuffer(address.length * 4);
for (int i = 0; i < address.length; i++) {
    final int element = address[i] & 0xFF;
    if (0 != i) {
        sb.append('.');
    sb.append(element);
return sb.toString();
StringipToString(final byte[] bytes)
ip To String
final StringBuffer addrStr = new StringBuffer();
for (int cnt = 0; cnt < bytes.length; cnt++) {
    final int uByte = bytes[cnt] < 0 ? bytes[cnt] + 256 : bytes[cnt];
    addrStr.append(uByte);
    if (cnt < 3)
        addrStr.append('.');
return addrStr.toString();
...
StringIpToString(int address)
Convert an IP address stored in an int to its string representation.
StringBuffer sa = new StringBuffer();
for (int i = 0; i < 4; i++) {
    sa.append(0xff & address >> 24);
    address <<= 8;
    if (i != 4 - 1)
        sa.append('.');
return sa.toString();
...
StringIPToString(int intIP)
IP To String
StringBuilder sb = new StringBuilder(15);
try {
    for (int i = 3; i >= 0; i--) {
        if (i != 3)
            sb.append('.');
        sb.append((int) (intIP & 0xFF));
        intIP = intIP >>> 8;
} catch (Exception e) {
    e.printStackTrace();
return (sb.toString());