java lambda表达式(比较器)

package spss;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Comparator;
import java.util.Locale;
import java.util.concurrent.PriorityBlockingQueue;

/**
 * @Author lyr
 * @create 2020/3/16 19:36
 */
public class Test {
    public static void main(String[] args) {
        PriorityBlockingQueue q
                = new PriorityBlockingQueue(10, Comparator.comparingInt((Integer i)-> i).reversed());
        for(int i=0;i<=3;++i) {
            q.put(i);
        }
        try {
            System.out.println("卡住了e");
            System.out.println(q.take());
            System.out.println("结束了e");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

复习一下lambda 表达式的写法

package spss;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Comparator;
import java.util.Locale;
import java.util.concurrent.PriorityBlockingQueue;

/**
 * @Author lyr
 * @create 2020/3/16 19:36
 */
public class Test {
    public static void main(String[] args) {
        PriorityBlockingQueue q
                = new PriorityBlockingQueue(10, Comparator.comparingInt(Integer::intValue).reversed());
        for(int i=0;i<=3;++i) {
            q.put(i);
        }
        try {
            System.out.println("卡住了e");
            System.out.println(q.take());
            System.out.println("结束了e");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

你可能感兴趣的:(CRUD)