Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get ArrayList<HashMap<String, String>> values

In my first activity I have the next code:

ArrayList<HashMap<String, String>> list_params = new ArrayList<HashMap<String, String>>();
            HashMap<String, String> param_aux = new HashMap<String, String>();

            param_aux.put("language", Integer.toString(language_spinner.getSelectedItemPosition()));
            param_aux.put("city", city_edittext.getText().toString());

list_params.add(param_aux);

And in my second activity I want to get the values, so my code is:

ArrayList<HashMap<String, String>> list_params_ = new ArrayList<HashMap<String, String>>();
    list_params_= (ArrayList<HashMap<String, String>>) getIntent().getSerializableExtra("list_params");

    System.out.println("...serialized data.."+list_params_);

If I chech the System.out, the values are correct sent but I want to get a specific value of the HashMap (example: city value).

...serialized data..[{weekend_midday_check=1, weekend_afternoon_check=0, weekend_morning_check=1, sort_by=0, language=0, weekly_afternoon_check=1, weekly_morning_check=1, weekly_midday_check=1, city=Terrassa}]

How can I get the value for the city sent in the first activity?

like image 763
MarcForn Avatar asked Sep 29 '13 20:09

MarcForn


People also ask

Can the value of a HashMap be an ArrayList?

A HashMap contains key-value pairs, there are three ways to convert a HashMap to an ArrayList: Converting the HashMap keys into an ArrayList. Converting the HashMap values into an ArrayList.

Are Hashmaps faster than ArrayList?

The ArrayList has O(n) performance for every search, so for n searches its performance is O(n^2). The HashMap has O(1) performance for every search (on average), so for n searches its performance will be O(n). While the HashMap will be slower at first and take more memory, it will be faster for large values of n.

Can we get key from value in HashMap?

If your hashmap contain unique key to unique value mapping, you can maintain one more hashmap that contain mapping from Value to Key. In that case you can use second hashmap to get key.


1 Answers

Use:

list_params_.get(0).get("city");
like image 84
Ryan S Avatar answered Sep 18 '22 11:09

Ryan S