Java program to delete a node from the beginning of the singly linked list17 Mar 2025 | 3 min read In this program, we will create a singly linked list and delete a node from the beginning of the list. To accomplish this task, we need to make the head pointer pointing to the immediate next of the initial node which will now become the new head node of the list. ![]() Consider the above example; Node was the head of the list. Make head to point to next node in the list. Now, node 1 will become the new head of the list. Thus, deleting the Node. Algorithm
a. deleteFromStart() will delete a node from the beginning of the list:
a. display() will display the nodes present in the list:
Program:Output: Original List: 1 2 3 4 Updated List: 2 3 4 Updated List: 3 4 Updated List: 4 Updated List: List is empty Next TopicJava Programs |
The singly linked list is a linear data structure in which each element of the list contains a pointer which points to the element in the list. Each element in the singly linked list is called a node. Each node has two components: data...
5 min read
Selection sort is an easy-to-understand and straightforward kind of algorithm that sorts elements in a list or array, either ascending or descending. The element idea at the core of selection sort is to obtain repeatedly the minimum (or the maximum) element of the unsorted part...
7 min read
In this program, we need to find out the total number of binary search trees can be constructed with n values. Below diagram shows a possible binary search tree with the key value as 3. So, we can construct a total of five binary search...
3 min read
Java Convert String to int We can convert String to an int in java using Integer.parseInt() method. To convert String into Integer, we can use Integer.valueOf() method which returns instance of Integer class. Scenario It is generally used if we have to perform mathematical operations on the string which...
2 min read
In this program, we need to swap two strings without using a third variable. Str1: Good Str2: morning Swapping two strings usually take a temporary third variable. One of the approach to accomplish this is to concatenate given two strings into first string. Str1Str1 = Str1 + Str2=...
2 min read
Java Program to find Third Largest Number in an Array We can find the third largest number in an array in java by sorting the array and returning the 3nd largest number. Let's see the full example to find the third largest number in java array. public class...
2 min read
How to Reverse a String in Java Word by Word In this section, we reverse a string in Java word by word. Example 1: Reverse a string word by word using recursion import java.util.Scanner; public class ReverseStringExample1 { public static void main(String[] args) { String str; System.out.println("Enter a string: "); Scanner scanner =...
1 min read
In this section, we will learn what is a strontio number and also create Java programs to check if the given number is strontio. The strontio number program frequently asked in Java coding tests and academics. Strontio Number Strontio numbers are those four digits numbers when multiplied by...
3 min read
In this program, we need to find out the maximum width of the binary tree. The width of the binary tree is the number of nodes present in any level. So, the level which has the maximum number of nodes will be the maximum width...
6 min read
In this section, we have covered different logics in Java programs to find GCD of two numbers. Greatest Common Divisor: It is the highest number that completely divides two or more numbers. It is abbreviated for GCD. It is also known as the Greatest Common Factor (GCF)...
4 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