Here I have a requirement to display the ArrayList items in Ascending order in a RecyclerView.
RestaurantsModel is a model class which will have the getters and
setter methods of the attributes.
List<RestaurantsModel> restaurantsList = response.body(); //Sort list items into alphabetical order..Collections.sort(restaurantsList, new Comparator<RestaurantsModel>() { @Override public int compare(RestaurantsModel modelObj1, RestaurantsModel modelObj2) { String s1 = modelObj1.getName(); String s2 = modelObj2.getName(); return s1.compareToIgnoreCase(s2); } });

No comments:
Post a Comment