高创园网站建设方案,网站设计的要素,仿克米设计网站,wordpress+内容分发Java 一个数组集合List 赋值给另一个数组集合List #xff0c;两个数组集合属性部分一致。 下面是一个Demo, 具体要根据自己的业务调整。 import java.util.ArrayList;
import java.util.List;class People {private String name;private int age;private String address;publ…Java 一个数组集合List 赋值给另一个数组集合List 两个数组集合属性部分一致。 下面是一个Demo, 具体要根据自己的业务调整。 import java.util.ArrayList;
import java.util.List;class People {private String name;private int age;private String address;public People(String name, int age, String address) {this.name name;this.age age;this.address address;}// 省略getter和setter方法
}class NewPeople {private String name;private int age;public NewPeople(String name, int age) {this.name name;this.age age;}// 省略getter和setter方法
}public class Main {public static void main(String[] args) {ListPeople peopleList new ArrayList();peopleList.add(new People(张三, 30, 北京));peopleList.add(new People(李四, 20, 上海));peopleList.add(new People(王五, 50, 广州));ListNewPeople newPeopleList new ArrayList();for (People people : peopleList) {NewPeople newPeople new NewPeople(people.getName(), people.getAge());newPeopleList.add(newPeople);}// 输出newPeopleListfor (NewPeople newPeople : newPeopleList) {System.out.println(姓名 newPeople.getName() 年龄 newPeople.getAge());}}
}