JAVA链接列表搜索链接列表将数据与用户输入的数据进行比较?

all*_*ded 0 java linked-list

我有一个链表.里面的一切都很美好.我唯一的问题是如何将变量与内容进行比较以查看它们是否匹配.

例如,我有一个充满名字的链表.我希望用户能够输入名称并搜索链接列表中是否存在该名称.

用户输入:Johnny

程序检查Johnny是否存在于链接列表中.

我没有这方面的代码,因为我不确定它会是什么.

public static LinkedList<String> NameList1 = new LinkedList<String>(); // How do I search its contents?
Run Code Online (Sandbox Code Playgroud)

非常感谢!!

Ern*_*ill 5

使用界面中的contains()方法List.

if (NameList1.contains("Johnny")) {
    // code to execute if Johnny is in the list
}
Run Code Online (Sandbox Code Playgroud)