While using the android-async-http
library I stumbled upon params.add()
.
I've been using params.put()
for a while and it seems better than add()
since it allows data types other than String (like int, long, object, file) while add()
does not.
RequestParams params = new RequestParams();
// So how is this
params.add("param_a", "abc");
// different from this
params.put("param_a", "abc");
// and which one should I use?
The major difference between the two (other than
add()
's String-only support) is thatput()
overwrites the previous presence ofparam
with an existing key whileadd()
does not.For example:
While add creates two
params
with the same key:But what is the importance of doing this?
In the above example, the web-server would only read the last value of
key
i.e.xyz
and notabc
but this is useful when POSTing arrays: