Is there a right way to build a URL?
You can also use spring UriComponentsBuilder
UriComponentsBuilder
.fromUriString(baseUrl)
.queryParam("name", name)
.queryParam("surname", surname)
.build().toUriString();
You can use Apache URIBuilder
Sample code: Full Apache Example
URIBuilder builder = new URIBuilder()
.setScheme("http")
.setHost("apache.org")
.setPath("/shindig")
.addParameter("helloWorld", "foo&bar")
.setFragment("foo");
builder.toString();
Output: http://apache.org/shindig?helloWorld=foo%26bar#foo