Online Java Compiler By
JavaTpoint.com
import java.net.URL; public class URLgetHostExample3 { public static void main(String args[])throws Exception { //passing url in URL class URL url1=new URL("https://www.javatpoint.com/"); //Adding file name with url1 URL url2=new URL(url1,"/URL-class"); URL url3=new URL(url1,"/URLConnection-class"); System.out.println("Url1: "+url2); System.out.println("Url2: "+url2); // Fetching Host name String s=url2.getHost(); if(s.equals(url3.getHost())) System.out.println("Both url has Same host name "); } }
Output