Predefined comparator for string

TypeFieldSummary
static Comparator<String>CASE_INSENSITIVE_ORDERA Comparator that orders String objects as by compareToIgnoreCase.

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {
  public static void main(String[] argv) {
    List<String> list = new ArrayList<String>();
    list.add("java2s.com");
    list.add("Java2s.com");
    list.add("A");
    list.add("a");
  
    Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
 
    System.out.println(list);
  }
}
  

The output:


[A, a, java2s.com, Java2s.com]
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.