Here you can find the source of getHostName(String address)
public static String getHostName(String address)
//package com.java2s; //License from project: Apache License import java.net.*; import java.util.HashMap; import java.util.Map; public class Main { private static final Map<String, String> hostNameCache = new HashMap<String, String>(1000); public static String getHostName(String address) { try {//from w w w . java 2 s .c o m int i = address.indexOf(':'); if (i > -1) { address = address.substring(0, i); } String hostname = hostNameCache.get(address); if (hostname != null && hostname.length() > 0) { return hostname; } InetAddress inetAddress = InetAddress.getByName(address); if (inetAddress != null) { hostname = inetAddress.getHostName(); hostNameCache.put(address, hostname); return hostname; } } catch (Throwable e) { // ignore } return address; } }