Apex provides comparable interface with compareTo method which can be used sort wrapper class.
You can write your comparison logic in compareTo method to sort wrapper.
Below is sample wrapper class, user-defined data type which implements comparable interface.
Below is sample code which you can run in developer console in execute anonymous block.
List<SK_sortUtilityTestWrapper> wrapperList= new List<SK_sortUtilityTestWrapper>();
wrapperList.add(new SK_sortUtilityTestWrapper('D',50.6));
wrapperList.add(new SK_sortUtilityTestWrapper('A',40));
wrapperList.add(new SK_sortUtilityTestWrapper('B',44.2));
system.debug('****wrapperlist before sorting:'+wrapperList);
wrapperList.sort();
system.debug('****wrapperlist after sorting:'+wrapperList);
Logs:
You can write your comparison logic in compareTo method to sort wrapper.
Below is sample wrapper class, user-defined data type which implements comparable interface.
Below is sample code which you can run in developer console in execute anonymous block.
List<SK_sortUtilityTestWrapper> wrapperList= new List<SK_sortUtilityTestWrapper>();
wrapperList.add(new SK_sortUtilityTestWrapper('D',50.6));
wrapperList.add(new SK_sortUtilityTestWrapper('A',40));
wrapperList.add(new SK_sortUtilityTestWrapper('B',44.2));
system.debug('****wrapperlist before sorting:'+wrapperList);
wrapperList.sort();
system.debug('****wrapperlist after sorting:'+wrapperList);
Logs:
Hope this will help!!!
They’re very good at educating their teams in best practices, and they know when to advise companies like us when we should be doing another way
ReplyDeleteweb design firm
They are a friendly team whose strong client communication skills have made for a pleasant partnership.
ReplyDeletebest UX designers
You guys present there are performing an excellent job.
ReplyDeletetop 10 web designing companies
This is one of the most important blogs that I have seen, keep it up!
ReplyDeletebest design agency
Working in a construction site has a lot of dangers and risks. This is because being a construction worker, you will need to do a lot of dangerous works such as cutting, riveting, sawing, building, and all other sorts of industrial activities. No matter how technically advanced the safety measures and work protocols are, there will always be a possibility that an accident will happen. remodeling contractors San Jose CA
ReplyDeleteSafe drivers know that they should be aware not only of the dangers of other drivers' negligent behavior, but also of the potential hazards that exist out on the highways. Ongoing construction can present particularly dangers situations, both to drivers and to the workers on site, since there are many hazards present that can potentially cause harm. A construction project can change the familiar nature of roads and can present obstacles that surprise drivers. If the road construction is not properly maintained, repaired, or replaced, it can lead to potential accidents and injuries. concrete driveway lansing mi
ReplyDelete“It’s always good to learn tips like you share for blog posting. As I just started posting comments for blog and facing problem of lots of rejections. I think your suggestion would be helpful for me. I will let you know if its work for me too.” Get a free quote
ReplyDeleteI am incessantly thought about this, thanks for putting up. Kalamazoo Handyman Crew
ReplyDeleteI went over this site and I believe you have a lot of superb information, saved to bookmarks (:. handyman services lansing mi
ReplyDeleteSome really wondrous work on behalf of the owner of this site, perfectly great subject material . handyman lansing mi
ReplyDeleteHighly vigorous blog, I liked that much.
ReplyDeletelearn noorani qaida
The Comparable interface provides a convenient way to sort wrapper classes like Lists of user-defined types. It simplifies sorting operations and enhances code readability. Leveraging this interface, programmers can efficiently organize data structures. For further insights, consult with the best assignment writers who can offer valuable guidance on this topic.
ReplyDelete