LinkedList对象的pop()方法 (LinkedList Object pop() method)
This method is available in package java.util.LinkedList.pop().
软件包java.util.LinkedList.pop()中提供了此方法。
This method is used to delete or remove or return or pop an object at the top of the stack(initial or first position) represented by the linked list.
此方法用于删除或删除或返回或弹出位于链表所表示的堆栈顶部(初始或第一位置)的对象。
This method is equivalent to remove() or removeFirst() of the LinkedList.
此方法等效于LinkedList的remove()或removeFirst() 。
This method will throw an exception if List is empty.
如果List为空,则此方法将引发异常。
Syntax:
句法:
Object pop(){
}
Parameter(s):
参数:
We don't pass any object as a parameter in the method of the linked list.
在链接列表的方法中,我们不传递任何对象作为参数。
Return value:
返回值:
The return type of this method is Object that means this method returns Object (i.e. it return the top element of the stack represented by the LinkedList).
该方法的返回类型为Object,这意味着该方法返回Object(即,它返回由LinkedList表示的堆栈的顶部元素)。
Java程序,演示LinkedList pop()方法的示例 (Java program to demonstrate example of LinkedList pop() method)
import java.util.LinkedList;
public class LinkList {
public static void main(String[] args) {
LinkedList list = new LinkedList();
// use add() method to add elements in the list
list.add("J");
list.add("A");
list.add("V");
list.add("A");
// Current list Output
System.out.println("The Current list is:" + list);
// Remove or Pop first element from the linked list
// and new list output after implementing pop()
System.out.println("The new List after pop() method is:" + list.pop());
}
}
Output
输出量
D:\Programs>javac LinkList.java
D:\Programs>java LinkList
The Current list is:[J, A, V, A]
The new List after pop() method is:J
翻译自: https://www.includehelp.com/java/linkedlist-object-pop-method-with-example.aspx