I think it quite simple but I need one ways to solve it easy.
My problem is: I have list object Student include 100 objects
public class Student {
private String id;
private String name;
private int age;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
Now, I only want to get age of some student has name "ABC", "BCD", "DEF"
So I will do it:
Map<String, String> data = new HashMap<>();
List<String> listSpecification = new ArrayList<>(Arrays.asList("ABC", "BCD", "DEF"));
for (Student stu : list<Student>) {
for (int i = 0; i < listSpecification.size(); i++) {
if (stu.getName().equalsIgnoreCase(listSpecification.get(i))) {
data.put(pro.getName(), pro.getValue());
}
}
}
But if I do it, I think it not good about performance. So anyone can help me another case ?