Here you can find the source of getLocalHostAddress()
public static String getLocalHostAddress()
//package com.java2s; import java.net.InetAddress; public class Main { private static InetAddress localhost = null; /**//from w ww . ja v a 2 s . c o m * Gets the set localhost address as URL string (ipv6 addresses are enclosed in []) * @return The localhost address */ public static String getLocalHostAddress() { byte[] addr = localhost.getAddress(); String localHostAddress = localhost.getHostAddress().replaceAll("%10", ""); if (addr.length == 16) { // ipv6 address localHostAddress = "[" + localHostAddress + "]"; } return localHostAddress; } }