You can use UriComponentsBuilder
and UriComponents
which facilitate making URIs
String url = "http://example.com/search";
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
params.add("name", "john");
params.add("location", "africa");
UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(url).queryParams(params).build();
System.out.println(uriComponents.toUri());
prints
http://example.com/search?name=john&location=africa
There are other options if you need to use URI variables for path segments.
Note that if you are sending an HTTP request, you need an valid URL. The HTTP URL schema is explained in the HTTP specification, here.
The UriComponentsBuilder
provides methods to build all parts of the URL.