import java.util.*;
public class SortTester {
  public static void main(String[] args) {
    String[] data = {"Tom", "Mike","Mary","Linda","Jack"};  
    List<String> names =  Arrays.asList(data);  
    
    //方式一：通过创建匿名的Comparator实例来排序
    Comparator<String> cp=new Comparator<String>() {  
      public int compare(String s1, String s2) {  
        return (s1.compareTo(s2));  
      }  
    };
    Collections.sort(names,cp);  
    	
    //方式二：用Lambda表达式来排序
    Comparator<String> sortByName=(String s1,String s2)->(s1.compareTo(s2));  
    Collections.sort(names, sortByName);  
  
    //方式三：用Lambda表达式来排序
    Collections.sort(names,(String s1,String s2)->(s1.compareTo(s2)));   
    	
    names.forEach(System.out::println); 	
  }
}

/****************************************************
 * 作者：孙卫琴                                     *
 * 来源：<<Java面向对象编程>>                       *
 * 技术支持网址：www.javathinker.net                *
 ***************************************************/

