• Java8-Lambda-No.01


    import java.util.Arrays;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.List;
    import java.util.Optional;
    
    public class Lambda1 {
    
        public static void main(String[] args) {
            List<String> names = Arrays.asList("peter", "anna", "mike", "xenia");
    
            Collections.sort(names, new Comparator<String>() {
                @Override
                public int compare(String a, String b) {
                    return b.compareTo(a);
                }
            });
    
            Collections.sort(names, (String a, String b) -> {
                return b.compareTo(a);
            });
    
            Collections.sort(names, (String a, String b) -> b.compareTo(a));
    
            Collections.sort(names, (a, b) -> b.compareTo(a));
    
            System.out.println(names);
    
            names.sort(Collections.reverseOrder());
    
            System.out.println(names);
    
            List<String> names2 = Arrays.asList("peter", null, "anna", "mike", "xenia");
            names2.sort(Comparator.nullsLast(String::compareTo));
            System.out.println(names2);
    
            List<String> names3 = null;
    
            Optional.ofNullable(names3).ifPresent(list -> list.sort(Comparator.naturalOrder()));
    
            System.out.println(names3);
        }
    
    }
  • 相关阅读:
    数据库客户端们
    tcl调用tuxedo的一个demo
    tcl实现http请求
    CHAP算法C++实现
    归一化数值
    PPPoE名词解释
    Prism MEF example
    为什么我们要开源
    WPF Issues
    WPF & EF & Prism useful links
  • 原文地址:https://www.cnblogs.com/bilaisheng/p/10210917.html
Copyright © 2020-2023  润新知