简体   繁体   English

如何在java中的列表中搜索?

[英]how to search in a list in java?

i have three list containing 3/4 items in each.我有三个列表,每个列表包含 3/4 个项目。 Now a node contains each those items.现在一个节点包含每个这些项目。 when the node is assigned to a particular item it has to search for that item in those list and should return the particular list containing that item.当节点被分配给特定项目时,它必须在这些列表中搜索该项目,并应返回包含该项目的特定列表。 How can i do this?我怎样才能做到这一点?

Try this : In case the试试这个:如果

if(listOne.contains(object))
            return listOne;

The list.contains() uses equals. list.contains() 使用 equals。 so, if list.contains() does not give you the expected result, you should be overriding the equals method.所以,如果 list.contains() 没有给你预期的结果,你应该覆盖 equals 方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM