'Better way of building query parameters to URI in JAVA
In order build a URI that makes a GET
request to a Server I'm using a Set
of Pair<String, String>
to build the query parameters. I pass the set as parameter to a function buildURL
and get the request URI in return.
Let's say Set<Pair<String, String>> queries
has values of {"id" : 2, "id" : 5, "id" : 8}
, then the buildURL receives the Set and returns "website.com/products?id=2&id=5&id=8
".
This is working fine but I wonder if I'm overcomplicating and there are lighter ways of doing this. How could be a better way of doing it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|