I want to convert HashMap to json array my code is as follow:
Map map = new HashMap();
map.put(
A map consists of key / value pairs, i.e. two objects for each entry, whereas a list only has a single object for each entry. What you can do is to extract all Map.Entry
Set entries = map.entrySet();
JSONArray mJSONArray = new JSONArray(entries);
Alternatively, sometimes it is useful to extract the keys or the values to a collection:
Set keys = map.keySet();
JSONArray mJSONArray = new JSONArray(keys);
or
List values = map.values();
JSONArray mJSONArray = new JSONArray(values);
Note: If you choose to use the keys as entries, the order is not guaranteed (the keySet() method returns a Set). That is because the Map interface does not specify any order (unless the Map happens to be a SortedMap).