URI uri = new URI("http://www.example.com"); String uriString = uri.toString(); System.out.println(uriString); // output: "http://www.example.com"
String uriString = "http://www.example.com/path?query=test#fragment"; URI uri = new URI(uriString); System.out.println(uri.getHost()); System.out.println(uri.getPath()); System.out.println(uri.getQuery()); System.out.println(uri.getFragment()); // output: "www.example.com" "/path" "query=test" "fragment"This method is part of the java.net package.