Best Answer

Well if you're using the build in LinkedList class, you can simply call list.removeLast().

But let's assume you're not:

class LinkedList {

LinkedListNode root;

public void removeLast() {

// special case for an empty list

if( root null ) {

root = null;



// iterate through list, starting at root

LinkedListNode last = null;

LinkedListNode current = root;

// when is null, current is the last element of this list and

// last will become the new last element

while( != null ) {

last = current;

current =;


// cut off current = null;


private class LinkedListNode {

Object data;

LinkedListNode next = null;



User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Delete a node of the last element in the linked list algorithm in java?
Write your answer...
Still have questions?
magnify glass
Related questions

How do you write a Java program to implement weighted queue using circular doubly linked list?

Add weights to the elements of the queue and use an algorithm to sort the queue every time an element is added.

Can you provide a solution to the diamond-square algorithm using Java and recursion?

Yes. It is possible to provide a solution to the diamond-square algorithm using Java and recursion.

What is the difference between an algorithm and java code?

In Java programming language, an algorithm refers to a sequence of instructions that have been specified to undertake a particular task within a certain time. An algorithm can take no or several inputs but will generate at least one output.

Java source code for median filter algorithm?

research is going on to develop a source code for median filtering using java

Sorting an array of numbers in java?

here you will a good example on java sorting algorithm application

How do you write algorithms of java programs?

Write a program that graphically demonstrates the shortest path algorithm

What do you do when it says you have no space o download the Java for the limewire to work what do you delete then?

You need to uninstall unused programs or delete old and unneeded movies or documents. Java will need about 80 MB free, if I recall.

Which of the class in package defines a method to delete a file?

The class in Java has a delete() method to delete the file. See related link for details.

What is java joptionpane?

Java's jOptionPane from the javax.swing library is a GUI element for, essentially, an option dialogue box.

How do you get TOOMANYItems for Minecraft?

%appdata% open mincraft java archive Delete METAINF Download TMI Ctrl+a & drag into your minecraft java archive

Do you need java 5 and 6?

No, you can delete the old one. Java does not remove old versions when it is updated, however I think they have fixed that now.

How do you write algorithm for java program?

An "algorithm" is a method to solve a problem. These methods are more or less independent of the language. First you think about how you will solve a certain problem, step by step. Then you translate this into a computer program.