List.forEach()
//调用列表
List<A> b= a.Findc();
recordList.forEach(bfOprStave -> {
b.forEach(lov -> {
if ((b.getId().trim()).equals(lov.getValue().trim())){
b.setName(lov.getMeaning());
}
});//条件遍历
});//List直接调用Iterable,直接遍历
forEach()是Interable接口的方法。Java容器中,所有的Collection子类(List、Set)会实现Iteratable接口以实现foreach功能。
小结
只是遍历集合或者数组,用foreach。
对集合中的值进行修改,确定循环次数,用for循环。
List 常用方法
boolean add(E e)//在集合末尾添加一个数据元素;
boolean add(int index, E e)//在集合的指定索引出添加一个数据元素;
E remove(int index)//删除集合中指定索引的元素;
boolean remove(Object e)//删除集合中的某个元素;
E get(int index)//获取集合中指定索引出的元素;
int size()//获取集合的大小(包含元素的个数)。