12:24 am - Thursday March 23, 2017

LinkedList to add element on output using Push() method

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

This Program is used to add element on output using Push() method.

Example Program

 


package com.example;

import java.util.*;

public class LinkedListPush {
	public static void main(String[] args) { // create a LinkedList
		LinkedList list = new LinkedList(); // add some elements
		list.add("Hello");
		list.add(2);
		list.add("Chocolate");
		list.add("10"); // print the list
		System.out.println("LinkedList:" + list); // push Element the list
		list.push("Element"); // print the list
		System.out.println("LinkedList:" + list);
	}
}

output:

LinkedList:[Hello, 2, Chocolate, 10]
LinkedList:[Element, Hello, 2, Chocolate, 10]

 

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.

Following is the declaration for java.util.LinkedList.push() method

public void push(E e)

Parameters

  • e — the element to push

Return Value

This method does not return any value.

Exception

  • NA

BACK

Filed in: Java Examples

Comments are closed.