LinkedList boolean offerFirst(E e)method Example Program


Inserts the specified element at the front of this list.

Program

package com.candidjava;

import java.util.LinkedList;

/**
 * 
 * @author : mohan
 * @description :The java.util.LinkedList.offerFirst(E e) method inserts the
 *              specified element at the front of this list.
 */
public class LinkedListOfferFirst {
	public static void main(String[] args) {
		LinkedList list = new LinkedList();
		list.add("anandh");
		list.add("hari");
		list.add("vinoth");
		list.add("mohan");
		list.add("kamal");
		System.out.println("LinkedList:" + list);
		list.offerFirst("SIVA");
		System.out.println("LinkedList:" + list);
	}
}

Output

LinkedList:[anandh, hari, vinoth, mohan, kamal]
LinkedList:[SIVA, anandh, hari, vinoth, mohan, kamal]

Explanation

public boolean offerFirst(E e)
Inserts the specified element at the front of this list.
Specified by:
offerFirst in interface Deque
Parameters:
e - the element to insert
Returns:
true (as specified by Deque.offerFirst(E))
Since:
1.6


Related Post

Comments


©candidjava.com