LinkedList void push(E e) method Example Program


Pushes an element onto the stack represented by this list. In other words, inserts the element at the front of this list.
This method is equivalent to addFirst(E).

Program

package com.candidjava;

import java.util.LinkedList;

/**
 * 
 * @author : mohan
 * @description :The java.util.LinkedList.push(E e) method pushes an element
 *              onto the stack represented by this list. In other words, inserts
 *              the element at the front of this list.
 */
public class LinkedListPush {
	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.push("ASWIN");
		System.out.println("LinkedList:" + list);
	}
}

Output

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

Explanation

public void push(E e)
Pushes an element onto the stack represented by this list. In other words, inserts the element at the front of this list.
This method is equivalent to addFirst(E).

Specified by:
push in interface Deque<E>

Parameters:
e - the element to push

Since:
1.6


Related Post

Comments


©candidjava.com