I have code:
List<ModelMap> nameCustomer = new ArrayList<ModelMap>();
for (int i=1;i<150;i++) {
ModelMap map = new ModelMap();
map.put("name", "nazwa " + i);
map.put("surname", "nazwisko " + i);
map.put("number", "123 ");
nameCustomer.add(map);
}
ModelMap[] result = new ModelMap[nameCustomer.size()];
ModelMap[] rowsArray = nameCustomer.toArray(result);
How can I sort nameCustomer (or rowsArray) by surname or number?
You can use the
Collections.sort(nameCustomer, comparator)method to sort your list. For that you have to write the code for your Comparator.The code for Comparator will be –I am assuming that you have a
getSurnamemethod written in your ModelMap class to get the surname. If not then write it to make the above code work.You can visit here for further help. Cheers !!