当前位置 : 主页 > 编程语言 > java >

Java-forEach-函数式循环

来源:互联网 收集:自由互联 发布时间:2022-07-04
一 forEach /** * @Author ZiFan * @Date 2021/4/12 23:12 * @Description */ public class ForEachDemo { public static void main ( String [] args ) { List Province provinces = new ArrayList (); provinces . add ( new Province ( "1" , "贵州" ,

一 forEach



/**
* @Author ZiFan
* @Date 2021/4/12 23:12
* @Description
*/
public class ForEachDemo {
public static void main(String[] args) {
List<Province> provinces=new ArrayList<>();
provinces.add(new Province("1","贵州","1005"));
provinces.add(new Province("2","黑龙江","1003"));
provinces.add(new Province("3","安徽","1002"));
provinces.add(new Province("4","内蒙古","1001"));
provinces.add(new Province("5","云南","1004"));

provinces.forEach(province -> {
province.setName(province.getName()+"_"+province.getLocalCode());
});
System.out.println(provinces);
}
}
//[Province(id=1, name=贵州_1005, localCode=1005), Province(id=2, name=黑龙江_1003, localCode=1003), Province(id=3, name=安徽_1002, localCode=1002), Province(id=4, name=内蒙古_1001, localCode=1001), Province(id=5, name=云南_1004, localCode=1004)]



【文章原创作者:韩国服务器租用 http://www.558idc.com/lg.html 复制请保留原URL】
网友评论