LinkedList boolean contains(Object o)方法 (LinkedList boolean contains(Object o) method)
This method is available in package java.util.Collection and here, Collection is an interface.
该方法在java.util.Collection包中可用,在这里, Collection是一个接口。
This method is declared in interface Collection and implemented by the LinkedList Class.
此方法在接口Collection中声明,并由LinkedList类实现。
This method is used to check or identify whether an element or Object exists or not in the Linked list.
此方法用于检查或标识“链接”列表中是否存在元素或对象。
In this method, if Object exists in the linked list then it returns true else false.
在此方法中,如果对象在链接列表中,则返回true,否则返回false。
Syntax:
句法:
boolean contains(Object o){
}
Parameter(s):
参数:
This method accepts one parameter.
此方法接受一个参数。
Return value:
返回值:
The return type of this method is boolean that means this method returns true if the searched element is present in the linked list else it will return false after execution.
此方法的返回类型为boolean ,这意味着如果搜索到的元素存在于链表中,则此方法返回true,否则执行后将返回false。
Java程序演示LinkedList contains(Object o)方法的示例 (Java program to demonstrate example of LinkedList contains(Object o) method)
import java.util.LinkedList;
public class LinkList {
public static void main(String[] args) {
// Create an object of linked list
LinkedList list = new LinkedList();
// use add() method to add few elements in the linked list
list.add(10);
list.add(20);
list.add(30);
list.add(40);
list.add(50);
// Current Linked list Output
System.out.println("The Current Linked List is :" + list);
// With the help of contains(Object o) we will check
// whether 20 exists or not exists in the linked list.
System.out.println("The contains() will return or false : " + list.contains(20));
}
}
Output
输出量
D:\Programs>javac LinkList.java
D:\Programs>java LinkList
The Current Linked List is :[10, 20, 30, 40, 50]
The Searching Element is:true
翻译自: https://www.includehelp.com/java/linkedlist-boolean-contains-object-o-method-with-example.aspx