是否有很好的方法可以在嵌套列表中查找对象?也许来自 Guava 的东西支持以下内容:
class PriceInfo() {
List<PriceType> types;
}
class PriceType() {
String value;
}
List<PriceInfo> infos;
如何执行:SELECT * from infos S WHERE S.types.value := 'TEST'
?
或者甚至在更多嵌套列表中查找元素。
最佳答案
嵌套循环(我删除了我的评论,因为无论如何你都需要嵌套循环):
for(PriceInfo info : infos){
for(PriceType type : info.types) {
if(type.value.equals("test") { }
}
}
您可能会得到一些与外部库一起使用的奇异语法糖,但最终它们总是会诉诸于循环遍历每个项目。
关于java - 如何在嵌套列表中查找特定对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19684491/