LinkedList addLast() Method in Java
The addLast(E element) method of LinkedList appends the specified element at the end of this linked list. It does not return anything.
Syntax
void addLast(E e)
Parameters
e is the element to be added to the linked-list
Return Value
It doesn't return anything
Program
import java.util.LinkedList; public class LinkedListAddLastExample { public static void main(String[] args) { LinkedListoddNumbers = new LinkedList(); oddNumbers.add(5); oddNumbers.add(7); oddNumbers.add(9); oddNumbers.add(11); System.out.println("Linked List elements: " + oddNumbers); oddNumbers.addLast(13); System.out.println("Linked List elements after adding 13 at last position: " + oddNumbers); } }
Output
Linked List elements: [5, 7, 9, 11] Linked List elements after adding 13 at last position: [5, 7, 9, 11, 13]
0 Comments