Say I have a URL
http://example.com/query?q=
and I have a query entered by the user such as:
random word £500 bank
You can use the follwing code.
String encodedUrl1 = UriUtils.encodeQuery(query, "UTF-8");//not change
String encodedUrl2 = URLEncoder.encode(query, "UTF-8");//changed
String encodedUrl3 = URLEncoder.encode(query, StandardCharsets.UTF_8.displayName());//changed
System.out.println("url1 " + encodedUrl1 + "\n" + "url2=" + encodedUrl2 + "\n" + "url3=" + encodedUrl3);