String queryValue = "apples & oranges"; String encodedValue = Uri.encode(queryValue); // Result: "apples%20%26%20oranges"
MapIn both examples, `Uri.encode` is used to encode special characters such as spaces and ampersands. The `android.net.Uri` class is part of the Android framework, specifically the `android` package.queryMap = new HashMap<>(); queryMap.put("fruit", "apples & oranges"); queryMap.put("color", "red, green & orange"); String encodedQueryParams = queryMap.entrySet().stream() .map(entry -> entry.getKey() + "=" + Uri.encode(entry.getValue())) .collect(Collectors.joining("&")); // Result: "fruit=apples%20%26%20oranges&color=red%2C%20green%20%26%20orange"