Monday, 12 May 2014

LinkedList : offer : Add element to the tail of list

public boolean offer(E e)
Adds the specified element as the tail (last element) of this list. Returns true if the element added successfully.

import java.util.*;

class LinkedListOffer{
 public static void main(String args[]){
  LinkedList<Integer> myList;
  myList = new LinkedList<> ();
  
  /* Add Elements to myList */
  myList.offer(10);
  myList.offer(20);
  myList.offer(30);
  myList.offer(40);
  
  System.out.println("Elements in myList are");
  System.out.println(myList);
 }
}

Output
Elements in myList are
[10, 20, 30, 40]


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment