File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
collections/linkedlist/check-if-linkedlist-contains-an-element Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .gaurav .ExProject .LinkedList ;
2+
3+ import java .util .LinkedList ;
4+
5+ /**
6+ * A Java program to check if the element is present
7+ * in the linkedList using the contains(Object o) method.
8+ *
9+ * @author coderolls.com
10+ *
11+ */
12+ public class LinkedListContains {
13+
14+ public static void main (String [] args ) {
15+
16+ LinkedList <String > linkedList = new LinkedList <String >();
17+
18+ linkedList .add ("Uber" );
19+ linkedList .add ("Ola" );
20+ linkedList .add ("Didi" );
21+ linkedList .add ("Lyft" );
22+ linkedList .add ("Yandex" );
23+
24+ System .out .println ("LinkedList is as follows: \n " + linkedList );
25+
26+
27+ // checks if the linkedList contains "Ola"
28+ // returns true if present
29+ boolean isOlaPresnet = linkedList .contains ("Ola" ); // true
30+
31+ System .out .println ("\n Check if linkedList contains Ola: " + isOlaPresnet );
32+
33+ // checks if the linkedList contains "Grab"
34+ // returns true if present
35+ boolean isGrabPresnet = linkedList .contains ("Grab" ); // false
36+
37+ System .out .println ("\n Check if linkedList contains Grab: " + isGrabPresnet );
38+
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments