Java Program to search an element in a singly linked list17 Mar 2025 | 3 min read In this program, we need to search a node in the given singly linked list. Identity Matrix ![]() To solve this problem, we will traverse through the list using a node current. Current points to head and start comparing searched node data with current node data. If they are equal, set the flag to true and print the message along with the position of the searched node. For e.g., In the above list, a search node says 4 which can be found at the position 4. Algorithm
a. searchNode() will search for a node in the list:
a. display() will display the nodes present in the list:
Program:Output: Element is present in the list at the position: 2 Element is not present in the list Next TopicJava Programs |
Java Program to find the frequency of odd & even numbers in the given matrix In this program, we need to find the frequencies of odd and even numbers present in the matrix. In the above example, all odd numbers are represented by the blue square and...
3 min read
In this program, we will create a singly linked list and delete a node from the middle of the list. To accomplish this task, we will calculate the size of the list and then divide it by 2 to get the mid-point of the list....
5 min read
Java Convert String to Object We can convert String to Object in java with assignment operator. Each class is internally a child class of Object class. So you can assign string to Object directly. You can also convert String to Class type object using Class.forName() method. Java String to...
1 min read
In this program, we create a doubly linked list and insert a new node in the middle of list. If list is empty, both head and tail will point to new node. If list is not empty, then we will calculate the size of the...
8 min read
In this program, we create a circular linked list and search a node in the list. 9->5->2->7->3 Consider, above example. Suppose we need to search for node 5. To solve this problem, we will iterate through the list and compare each node with 5. If match is...
5 min read
Java Convert Octal to Decimal We can convert octal to decimal in java using Integer.parseInt() method or custom logic. Java Octal to Decimal conversion: Integer.parseInt() The Integer.parseInt() method converts a string to an int with the given radix. If you pass 8 as a radix, it converts an octal...
2 min read
In this program, we will create a circular linked list and delete a node from the end of the list. If the list is empty, it will display the message "List is empty". If the list is not empty, we will loop through the list...
6 min read
Java program to print the following pattern on the console In this program, we are creating a right-angled triangle of numbers in increasing order. We are creating two loops, and 2nd loop is executing according to the first loop, inside 2nd loop printing the number row-wise...
2 min read
In the world of computer science, searching algorithms are fundamental techniques for retrieving information from data structures. One of the simplest and most intuitive searching algorithms is the linear search. Linear search is used to search a key element from multiple elements. Linear search is...
4 min read
Java program to print the following pattern on the console Algorithm: STEP 1: START STEP 2: SET i =1.REPEAT STEP 3 to 7UNTIL i<=10. STEP 3: SET j=1.REPEAT STEP 4 and 5UNTIL j<=10. STEP 4: if(i==0 or i==10 or j==0 or j==10) then PRINT 1 else PRINT "" STEP 5: SET...
1 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India