Java URL.getAuthority()

Syntax

URL.getAuthority() has the following syntax.

public String getAuthority()

Example

In the following code shows how to use URL.getAuthority() method.


import java.io.IOException;
import java.net.URL;
//from  w w  w  . j  a  v a  2s. co m
public class Main {

  public static void main(String[] args) {
    try {
      URL url = new URL("http://www.java2s.com/query?abc=def");
      System.out.println("URL is " + url.toString());
      System.out.println("authority is " + url.getAuthority());
      System.out.println("default port is " + url.getDefaultPort());
      System.out.println("query is " + url.getQuery());
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.net »




CookieManager
CookiePolicy
CookieStore
DatagramPacket
DatagramSocket
HttpCookie
HttpURLConnection
InetAddress
JarURLConnection
MulticastSocket
ServerSocket
Socket
SocketAddress
URI
URL
URLConnection
URLDecoder
URLEncoder