The example below converts URL to URI.

Java Code:
        URL url = null;
        URI uri = null;
        String urlString = "http://www.java-forums.org:80/sendmessage.php";
        
        // Create a URL object
        try {
            url = new URL(urlString);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

        try {
            uri = new URI(url.toString());
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }

        System.out.println("Original URL  : " + url);
        System.out.println("Converted URI : " + uri);