code: public static String toAddrString(InetAddress ip) {
          requireNonNull(ip, "ip");
          if (ip instanceof Inet4Address) {
              // For IPv4, Java's formatting is good enough.
              byte[] bytes = ip.getAddress();
              return (bytes[0] & 0xff) + "." + (bytes[1] & 0xff) + "." + (bytes[2] & 0xff) + "." + (bytes[3] & 0xff);
          }
          if (!(ip instanceof Inet6Address)) {
              throw new IllegalArgumentException("ip");
          }
          byte[] bytes = ip.getAddress();
          int[] hextets = new int[IPV6_PART_COUNT];
          for (int i = 0; i < hextets.length; i++) {
              hextets[i] =  (bytes[2 * i] & 255) << 8 | bytes[2 * i + 1] & 255;
          }
          compressLongestRunOfZeroes(hextets);
          return hextetsToIPv6String(hextets);
      }
docs: Returns the string representation of an {@link InetAddress}.
  
  <p>For IPv4 addresses, this is identical to
  {@link InetAddress#getHostAddress()}, but for IPv6 addresses, the output
  follows <a href="http://tools.ietf.org/html/rfc5952">RFC 5952</a>
  section 4.  The main difference is that this method uses "::" for zero
  compression, while Java's version uses the uncompressed form.
  
  <p>This method uses hexadecimal for all IPv6 addresses, including
  IPv4-mapped IPv6 addresses such as "::c000:201".  The output does not
  include a Scope ID.
  
  @param ip {@link InetAddress} to be converted to an address string
  @return {@code String} containing the text-formatted IP address
  @since 10.0