Monday, 26 October 2015

How to sort list of case insensitive strings?

Sort list of strings - case insensitive

To sort list of strings ignoring the case

Using java library flag


Collections.sort(list, String.CASE_INSENSITIVE_ORDER);


By passing own comparator


Collections.sort(list, new Comparator<String>() {
     @Override
     public intcompare(String s1, String s2) {
           returns1.compareToIgnoreCase(s2);
     }
});

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...