首页 > 代码库 > java lambda表达式

java lambda表达式

        ArrayList<String> list = new ArrayList<String>();
        list.add(0, "b");
        list.add(1, "a");
        list.add(0, "c");
        list.add(1, "d");
ITopable<String> sortDesc = ((strList) -> {
                String tmp = null;
                for (String item : strList) {
                    if (tmp == null) {
                        tmp = item;
                        continue;
                    }
                    if (item.compareTo(tmp) > 0) {
                        tmp = item;
                    }
                }
                return tmp;
            });
            String top = sortDesc.Top(list);
            System.out.println(String.format("最大值为:%s", top));
@FunctionalInterface
interface ITopable<T> {
    T Top(List<T> list);
}
            list.sort((s1, s2) -> {
                return s1.compareTo(s2);
            });

 

  list.forEach(s -> {
                System.out.println(s);
            });

 

java lambda表达式