How to convert List<NameValuePair> into a hashMap<String, String>?

Donshon

I'm capturing parameters from a request url using com.apache.http.NameValuePairwhich 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?

Jernej K

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to convert List<NameValuePair> into a List<Map.Entry<String, String>>?

From Dev

Convert Map<String, String> to List<NameValuePair> - is this the most efficient?

From Dev

How to convert a List<String[]> of Subtitle Structure to HashMap<String, List<String[]>>

From Java

How to convert Values in a Hashmap to a List<String>

From Java

How to convert String into Hashmap in java

From Dev

How to convert Json String to HashMap?

From Dev

Create a json string with List<NameValuePair> in android

From Dev

Convert a HashMap<Integer, List<String>> to HashMap<String, HashSet<Integer>>

From Dev

How to Convert ArrayList<HashMap<String, String>> to a StringArray?

From Java

Convert List<HashMap<String, Object>> to stream

From Dev

How to convert a string to a list of string?

From Dev

Convert list of payloads with a property List<String> to HashMap<String, Payload)

From Dev

Convert String to HashMap<String,String[]>

From Dev

How to solve NameValuePair cannot be a String in Android

From Dev

How store/save HashMap<String, List<String>>

From Dev

How to convert a list into a string?

From Dev

How to convert list to string?

From Dev

How to convert string into list?

From Dev

How to convert a string to a list?

From Dev

convert TreeMap<String,Object> to List<HashMap<String,Object>>

From Java

How to convert a List<String> list to csv string

From Java

Java: how to convert HashMap<String, Object> to array

From Java

How to convert untyped Object to HashMap<String,Object>

From Dev

how to convert List<Map<String, String>> to Map<String, List<String>>

From Dev

Convert String to Hashmap in RUST

From Java

Convert a JSON String to a HashMap

From Dev

Convert hashmap to string

From Dev

Convert String to Hashmap in Java

From Dev

Convert String to HashMap

Related Related

  1. 1

    How to convert List<NameValuePair> into a List<Map.Entry<String, String>>?

  2. 2

    Convert Map<String, String> to List<NameValuePair> - is this the most efficient?

  3. 3

    How to convert a List<String[]> of Subtitle Structure to HashMap<String, List<String[]>>

  4. 4

    How to convert Values in a Hashmap to a List<String>

  5. 5

    How to convert String into Hashmap in java

  6. 6

    How to convert Json String to HashMap?

  7. 7

    Create a json string with List<NameValuePair> in android

  8. 8

    Convert a HashMap<Integer, List<String>> to HashMap<String, HashSet<Integer>>

  9. 9

    How to Convert ArrayList<HashMap<String, String>> to a StringArray?

  10. 10

    Convert List<HashMap<String, Object>> to stream

  11. 11

    How to convert a string to a list of string?

  12. 12

    Convert list of payloads with a property List<String> to HashMap<String, Payload)

  13. 13

    Convert String to HashMap<String,String[]>

  14. 14

    How to solve NameValuePair cannot be a String in Android

  15. 15

    How store/save HashMap<String, List<String>>

  16. 16

    How to convert a list into a string?

  17. 17

    How to convert list to string?

  18. 18

    How to convert string into list?

  19. 19

    How to convert a string to a list?

  20. 20

    convert TreeMap<String,Object> to List<HashMap<String,Object>>

  21. 21

    How to convert a List<String> list to csv string

  22. 22

    Java: how to convert HashMap<String, Object> to array

  23. 23

    How to convert untyped Object to HashMap<String,Object>

  24. 24

    how to convert List<Map<String, String>> to Map<String, List<String>>

  25. 25

    Convert String to Hashmap in RUST

  26. 26

    Convert a JSON String to a HashMap

  27. 27

    Convert hashmap to string

  28. 28

    Convert String to Hashmap in Java

  29. 29

    Convert String to HashMap

HotTag

Archive