I'm capturing parameters from a request url using com.apache.http.NameValuePair
which basically store those params in List<NameValuePair>
. To do certain checks and verifications on those params, I need to convert that list into a HashMap<String, String>
. Is there a way to do this conversion?
Do you use Java 8? In that case you could make use of the Collectors.toMap() method:
Map<String, String> mapped = list.stream().collect(
Collectors.toMap(NameValuePair::getName, NameValuePair::getValue));
Otherwise you would have to loop through the elements
for(NameValuePair element : list) {
//logic to convert list entries to hash map entries
}
To get a better understanding, please take a look at this tutorial.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments