1.测试类
package io.renren.ceshi;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
/**
* @author youzo
*/
public class LambdaDemo {
public static void main(String[] args) {
Map<String,Object> map = Maps.newHashMap();
map.put("a1","a");
map.put("b1","b");
map.put("c1","c");
map.put("d1","d");
map.put("e1","e");
map.put("f1","f");
map.forEach((k,v)-> System.out.println("k="+k+":"+"v="+v));
System.out.println("===========================");
List<String> list = Lists.newArrayList();
list.add("aaa");
list.add("ccc");
list.add("bbb");
//用 Lambda 排序
list.sort(Comparator.naturalOrder());
list.forEach((v)-> System.out.println("v"+v));
}
}
2.输出结果
k=a1:v=a
k=f1:v=f
k=e1:v=e
k=d1:v=d
k=c1:v=c
k=b1:v=b
===========================
v=aaa
v=bbb
v=ccc