Java LinkedList offerLast(E e) Example

In this tutorial we will learn the usage of offerLast(E e) method of java.util.LinkedList class.This method will add the specified element to the end of the list. This will be almost same as the offer(E e) method.


public boolean offerLast(E e) 

Adds the specified element to the tail of the list and will return true if the insertion is successful.


The following example shows the usage of offerLast(e) method.

import java.util.Iterator;
import java.util.LinkedList;

public class OfferLastMethodLinkedListExample {
	public static void main(String args[])
	// Create LinkedList object
        LinkedList list1 = new LinkedList();
        //adding elements to list1
        list1.add("String 1");
        list1.add("String 2");
        list1.add("String 3");
        list1.add("String 4");
        //addding element to the tail of the list
        boolean insertion= list1.offerLast("String 88");
        //printing all the values of the LinkedList
        System.out.println("**Contents of the list**");
        Iterator iterator = list1.iterator();
        System.out.println("Is the insertion successful ?? "+insertion);


**Contents of the list**
String 1
String 2
String 3
String 4
String 88
Is the insertion successfuly?? true

Leave a Reply

Your email address will not be published. Required fields are marked *