java - Sort list of methods -


this question has answer here:

i have list contains setters of pojo class.

public static void main(string[] args) throws exception {      method[] publicmethods = sampleclass.class.getmethods();     list<method> setters = new arraylist<>();      (method method : publicmethods){         if (method.getname().startswith("set") && method.getparametercount() == 1) {             setters.add(method);         }     } } 

in documentation order of method list not guaranteed. question how can sort list of setters alphabetically?

you need custom comparator:

collections.sort(setters, new comparator<method> {   @override   public int compare(method a, method b) {     return a.getname().compareto(b.getname());   } }); 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -