Online Java Compiler By
JavaTpoint.com
import java.net.URL; import java.util.Scanner; public class UrlgetPortExample1 { public static void main(String args[])throws Exception { //passing url in URL class constructor URL url1=new URL("http://127.0.0.1:8080/apex/f?p=4500:1001:2075345827901807::NO::"); System.out.println("Url: "+url1); // Fetching port no from given url System.out.println("Port in given url is : "+url1.getPort()); } }
Output