
Java8支持使用Lambda语法对集合进行遍历,语法如下
List
1 2 3 4 5
|
allQuestions.forEach(question -> {
if (question.getType().getCode().equals(typeCode)) {
filterQuestions.add(question);
}
});
|
Map
1 2 3 4 5 6
|
items.forEach((k, v) -> {
System.out.println("Item : " + k + " Count : " + v);
if("E".equals(k)) {
System.out.println("Hello E");
}
});
|
近期评论