URL toExternalForm() method in Java with Examples Last Updated : 31 Dec, 2018 Comments Improve Suggest changes Like Article Like Report The toExternalForm() function is a part of URL class. The function toExternalForm() returns the string representation of a specified URL. The string is created by calling the toExternalForm() function of the stream protocol handler for this object. Function Signature: public String toExternalForm() Syntax: url.toExternalForm() Parameter: This function does not require any parameter Return Type: The function returns String Type Below programs illustrates the use of toExternalForm() function: Example 1: Given a URL we will to the string representation of the URL Java // Java program to show the // use of the function toExternalForm() import java.net.*; class Solution { public static void main(String args[]) { // url object URL url = null; try { // create a URL url = new URL("https:// www.geeksforgeeks.org"); // get the ExternalForm String _ExternalForm = url.toExternalForm(); // display the URL System.out.println("URL = " + url); // display the ExternalForm System.out.println(" String representation= " + _ExternalForm); } // if any error occurs catch (Exception e) { // display the error System.out.println(e); } } } Output: URL = https:// www.geeksforgeeks.org String representation= https:// www.geeksforgeeks.org Example 2: Java // Java program to show the // use of the function toExternalForm() import java.net.*; class Solution { public static void main(String args[]) { // url object URL url = null; try { // create a URL url= new URL("https:// www.geeksforgeeks.org#Arnab_Kundu"); // get the ExternalForm String _ExternalForm = url.toExternalForm(); // display the URL System.out.println("URL = " + url); // display the ExternalForm System.out.println(" String representation= " + _ExternalForm); } // if any error occurs catch (Exception e) { // display the error System.out.println(e); } } } Output: URL = https:// www.geeksforgeeks.org#Arnab_Kundu String representation= https:// www.geeksforgeeks.org#Arnab_Kundu Comment More infoAdvertise with us Next Article URL sameFile() method in Java with Examples A andrew1234 Follow Improve Article Tags : Java Java-Functions Java-net-package Java-URL Practice Tags : Java Similar Reads URL toURI() method in Java with Examples The getURI() function of URL class converts the URL object to a URI object. Any URL which compiles with RFC 2396 can be converted to URI. URLs which are not in the specified format will generate an error if converted to URI format. Function Signature public URI toURI() Syntax url.toURI() Parameter: 2 min read URL toURI() method in Java with Examples The getURI() function of URL class converts the URL object to a URI object. Any URL which compiles with RFC 2396 can be converted to URI. URLs which are not in the specified format will generate an error if converted to URI format. Function Signature public URI toURI() Syntax url.toURI() Parameter: 2 min read URL sameFile() method in Java with Examples The sameFile() function of Java.net.URL class is used to compare two URLs excluding the fragment part. This method returns true if both the URL are same excluding the fragment part else returns false. Function Signature public boolean sameFile(URL u) Syntax url1.sameFile(url2); Parameter: This metho 2 min read URL sameFile() method in Java with Examples The sameFile() function of Java.net.URL class is used to compare two URLs excluding the fragment part. This method returns true if both the URL are same excluding the fragment part else returns false. Function Signature public boolean sameFile(URL u) Syntax url1.sameFile(url2); Parameter: This metho 2 min read Path toUri() method in Java with Examples The toUri() method of java.nio.file.Path interface used to return a URI to represent this path. This method converts this path into an absolute URI with a scheme equal to the URI scheme that identifies the provider. The exact form of the scheme-specific part is highly provider dependent. In the scen 2 min read Path toUri() method in Java with Examples The toUri() method of java.nio.file.Path interface used to return a URI to represent this path. This method converts this path into an absolute URI with a scheme equal to the URI scheme that identifies the provider. The exact form of the scheme-specific part is highly provider dependent. In the scen 2 min read Like