Java API Tutorial - Java URL.getQuery()








Syntax

URL.getQuery() has the following syntax.

public String getQuery()

Example

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

import java.io.IOException;
import java.net.URL;
/*from  w w  w. j  a va2  s  .c o 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.