In this example we will show how to check if a specified element in the LinkedList in Java.
Source Code
package com.beginner.examples;
import java.util.LinkedList;
public class ElementInLinkedList {
public static void main(String[] args) {
LinkedList lists = new LinkedList();
lists.add("1");
lists.add("2");
boolean b = lists.contains("2"); // check if a specified element in the LinkedList
System.out.println(b);
}
}
Output:
true
References
Imported packages in Java documentation: