Java extract domain name or ip from string

String hostIP = "http://www.baidu.com/s/t";
hostIP = hostIP.replace("http://","").replace("https://",""); // Remove http and https prefix 
String [] arr = hostIP.split("/") ; // Separate by '/', take the first 
hostIP = arr[0];

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325857090&siteId=291194637