How do I update ArrayList<HashMap<String, ?>>?
quantity is String
values.get(position).put(KEY_POSITION, quantity);
Error:
The method put(String, capture#11-of ?) in the type HashMap is not applicable for the arguments (String, String)
So problem is related into logic of wildcards. Wildcard means "value type parameter can be anything" so HashMap<String, ?> is valid but here you're not able to put a String value into it.
Note: HashMap<String, ?> is same as HashMap<String, ? extends Object> so ? can be any type of class but String cannot be any type of class. This is reason of your error.
You need to make small change:
HashMap<String, ? super String>
Or as suggested @user902383 directly change1 (with same result) it into:
HashMap<String, String>
Now it will accept Strings.
1 String class is final (you can't extend from it) - for this reason it's better to use HashMap<String, String> First approach with HashMap<String, ? super String> is "useless" since you're not able to extend from String class.
HashMap<String, ? super String> can be replaced with HashMap<String, String> with same result as String is final and cant be extendedThe problem is you are using the wildcard "?". This is basically an unknown type. You should probably use String type instead, or Object if you need a more generic type. Like so:
ArrayList<HashMap<String, String>>
You can read more about it here: http://docs.oracle.com/javase/tutorial/extra/generics/wildcards.html and here: http://docs.oracle.com/javase/tutorial/extra/generics/morefun.html
Hope it helps.
Good luck
You can try toString implemented in the type of "quantity".
Otherwise simply, quantity + ""
String is not of type ?. It has nothing to do with quantity not being a String.