Java 查找列表是否包含相同的数据?
这里我想得到的是,如果Java 查找列表是否包含相同的数据?,java,database,Java,Database,这里我想得到的是,如果list.cust.getComponentIdentification()值包含相同的值,那么我想选取该值 for(CustomizableMenus cust : ra.getAction().getCustomizablemenu()){ cust.getComponentId(); cust.getComponentIdentification();
list.cust.getComponentIdentification()
值包含相同的值,那么我想选取该值
for(CustomizableMenus cust : ra.getAction().getCustomizablemenu()){
cust.getComponentId();
cust.getComponentIdentification();
cust.getComponentName();
cust.getComponentState();
custList.add(cust);
}
如果用户具有相同的
组件标识
,则我希望找到相应的组件标识。据我所知,您希望找到列表中的内容是否与用户具有的内容相同
假装有一个对象“用户”,你可以这样做:
User user = new User();
for (CustomizableMenus cust : ra.getAction().getCustomizablemenu()){
if (user.getComponentIdentification() == cust.getComponentIdentification()) {
// do whatever you need with it.
// you might also add a break here.
}
}
如果不是您所需要的,请告诉我,这样我可以改进我的答案。据我所知,您想知道列表中的内容是否与用户的内容相同 假装有一个对象“用户”,你可以这样做:
User user = new User();
for (CustomizableMenus cust : ra.getAction().getCustomizablemenu()){
if (user.getComponentIdentification() == cust.getComponentIdentification()) {
// do whatever you need with it.
// you might also add a break here.
}
}
如果这不是您所需要的,请告诉我,以便我可以改进我的答案。将它们流式传输并使用过滤器:
List<CustomizableMenus> found = ra.getAction().getCustomizablemenu()
.stream()
.filter(cm -> cm.getComponentIdentification().equals(componentIdentification))
.collect(Collectors.toList());
找到的列表=ra.getAction().getCustomizeleMenu()
.stream()
.filter(cm->cm.getComponentIdentification().equals(componentIdentification))
.collect(Collectors.toList());
对其进行流式处理并使用过滤器:
List<CustomizableMenus> found = ra.getAction().getCustomizablemenu()
.stream()
.filter(cm -> cm.getComponentIdentification().equals(componentIdentification))
.collect(Collectors.toList());
找到的列表=ra.getAction().getCustomizeleMenu()
.stream()
.filter(cm->cm.getComponentIdentification().equals(componentIdentification))
.collect(Collectors.toList());
1.你的英语不清楚。2.您使用的是什么java库?3.你可能不应该循环。对不起,我是英语周。。我使用的是1.8,我的目的是想找到列表中是否包含与我想找到的相同的cust.getComponentIdentification()值。请:编辑您的英语以便更清楚。了解。举例说明输入和输出。打个招呼。您正在使用的任何软件的全名是什么?您用来通过Java访问数据库的库的确切名称是什么?“1.8”不清楚。PS在你的答案中编辑澄清。评论是短暂的;你的英语不清楚。2.您使用的是什么java库?3.你可能不应该循环。对不起,我是英语周。。我使用的是1.8,我的目的是想找到列表中是否包含与我想找到的相同的cust.getComponentIdentification()值。请:编辑您的英语以便更清楚。了解。举例说明输入和输出。打个招呼。您正在使用的任何软件的全名是什么?您用来通过Java访问数据库的库的确切名称是什么?“1.8”不清楚。PS在你的答案中编辑澄清。评论是短暂的;它们不用于澄清。如果这回答了您的问题,请让我知道,我将编辑您的问题以使其更清楚。如果这回答了您的问题,请让我知道,我将编辑您的问题以使其更清楚。