The getQuery() function is a part of URI class. The function getQuery() returns the Query of a specified URI.
Function Signature
public String getQuery()
Syntax
uri.getQuery()
Parameter This function does not require any parameter
Return Type: The function returns String Type
Below programs illustrates the use of getQuery() function:
Example 1: Given a URI we will get the Query using the getQuery() function.
Output:
URI = https://www.geeksforgeeks.org/java/url-getprotocol-method-in-java-with-examples/
Query= title=protocol
Example 2: Now we will not provide any query and use the function to get the query and see the results.
Output:
URI = https://www.geeksforgeeks.org/java/url-getprotocol-method-in-java-with-examples/
Query=null
Example 3: The value returned by getQuery() and getRawQuery() is same except that all sequences of escaped octets are decoded.
The getRawPath() returns the exact value of the string as provided by the user but the getQuery() function decodes the sequence of escaped octets if any.