for(int i=0;i<videos.length();i++){
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = videos.getJSONObject(i);
map.put("id", String.valueOf(i));
map.put("title", e.getString("title"));
map.put("description", e.getString("description"));
mylist.add(map);
}
Hi, I am trying to sort the code above alphabetically. I know tree maps, are supposed to be used for this sorta thing, but it would be a bigger hassle to to do that. I am having errors arranging the hash map, and have looked at numerous examples.
It is not a big hassle to use a TreeMap.
Even if that’s a lot of hassle (e.g. if you made the mistake of declaring
mylistto be aList<HashMap>), you’ve got little choice. AHashMapis inherently unsorted / unordered and you can’t change that fact. If you could use aLinkedHashMapinstead, you could add the entries in alphabetical order, but if you can change the map type you may as well use aTreeMap.