I have the below HashMap
:
ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
Which uses the following keys:
static final String KEY_ITEM = "item"; // parent node
static final String KEY_ID = "id";
static final String KEY_NAME = "name";
static final String KEY_TITLE = "title";
static final String KEY_COST = "cost";
static final String KEY_DESC = "description";
static final String KEY_LINK = "link";
static final String KEY_PUBDATE = "pubDate";
static final String KEY_TIME = "pubDate";
I then use this piece of code, in order to populate the hashmap.
HashMap<String, String> map = new HashMap<String, String>();
map.put(KEY_ID, parser.getValue(e, KEY_ID));
//Get the title of the article.
map.put(KEY_NAME, parser.getValue(e, KEY_TITLE));
//Get the description of the article.
map.put(KEY_DESC, parser.getValue(e, KEY_DESC));
//Add the keys to the hashmap.
menuItems.add(map);
etc.....
I have a key called KEY_TIME
which houses the publish time for each article in the format 16:30
for example.
I wish to know how I would sort this hashmap, by the key KEY_TIME
, so that the artcicles at the top would be the most recent, and the ones at the bottom would be the oldest.
I know this has been asked before, but I can't find a solution which accounts for my ArrayList
before the Hashmap
.