java中处理List数据
这个list是动态的,想拿到的数据如图
想拿到
b=3 以及 b=6 的第一条数据
注:这个list是动态的,所以不要告诉我get(0) 和 get(1)这种写法。
求告知该怎么处理,谢谢!
for循环遍历result,判断sss这个对象的a和b字段
for(sss s : result) {
// 取 s的a和b进行判断
}
试试list的filter方法
List<Test> newList = list.parallelStream()
.filter(item -> item.getB() === 3 || item.getB() === 6).collect(Collectors.toList())
public List<SSS> testList(List<SSS> sssList){
List<SSS> result = new ArrayList<>();
SSS find_b3 = null;
SSS find_b6 = null;
for (SSS sss : sssList){
if (sss.b == 3) {
if (find_b3 == null) {
find_b3 = sss;
result.add(sss);
}
}
if (sss.b == 6){
if (find_b6 == null) {
find_b6 = sss;
result.add(sss);
}
}
if (find_b3 != null && find_b6 != null){
break;
}
}
return result;
}