Translate

Sunday, May 24, 2020

Code to sort the Arraylist elements/objects into Ascending order


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

Could not identify launch activity: Default activity not found : Error while Launching activity

Problem : I got this Error , When I tried to create an application without any Activity . Basically like to develop an Android Headless appl...