Java Program to Insert an Item at the Last of LinkedList Using the Offerlast() Method

You are currently viewing Java Program to Insert an Item at the Last of LinkedList Using the Offerlast() Method

Java program to insert an item at the last of LinkedList using the offerLast() method

// Java program to Insert an item at the last of LinkedList 
// using the offerLast() method

import java.util.LinkedList;

public class Main {
  public static void main(String[] args) {
    LinkedList list = new LinkedList();

    list.add(1);
    list.add("TWO");
    list.add(3);
    list.add("FOUR");
    list.add(true);

    System.out.println("List Items: \n" + list);

    // Insert an element at the last of LinkedList.
    list.offerLast(3.56);

    System.out.println("List Items: \n" + list);
  }
}

Output

List Items: 
[1, TWO, 3, FOUR, true]
List Items: 
[1, TWO, 3, FOUR, true, 3.56]

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply