LinkedList is doubly-linked list implementation of the List and Deque interfaces.
Java LinkedList push and pop operations.
Below example shows how to call push() and pop() methods on Java LinkedList.
push(): Pushes an element onto the stack represented by this list.
pop(): Pops an element from the stack represented by this list.
package com.walking.techie; import java.util.LinkedList; public class LinkedListPushPopDemo { public static void main(String[] args) { LinkedList<String> language = new LinkedList<String>(); language.add("C"); language.add("CPP"); language.add("JAVA"); language.add("DOTNET"); language.add("C#"); language.add("PHP"); System.out.println("Original language linked list " + language); // push operation language.push("Objective-C"); System.out.println("language linked list after push operation " + language); // pop operation language.pop(); System.out.println("language linked list after pop operation " + language); } }
Output of above program is shown below:
Original language linked list [C, CPP, JAVA, DOTNET, C#, PHP] language linked list after push operation [Objective-C, C, CPP, JAVA, DOTNET, C#, PHP] language linked list after pop operation [C, CPP, JAVA, DOTNET, C#, PHP]
No comments :
Post a Comment