AbstractSequentialList的remove(int index)方法用於從特定位置或索引的抽象順序列表中刪除元素。
用法:
AbstractSequentialList.remove(int index)
參數:參數index是整數數據類型,它指定要從AbstractSequentialList中移除的元素的位置。
返回值:此方法返回剛剛從列表中刪除的元素。
以下示例程序旨在說明AbstractSequentialList.remove(int index)方法:
程序1:
// Java code to illustrate remove() method
import java.util.*;
import java.util.AbstractSequentialList;
public class AbstractSequentialListDemo {
public static void main(String args[])
{
// Creating an empty AbstractSequentialList
AbstractSequentialList<String>
absqlist = new LinkedList<String>();
// Using add() method to add elements in the list
absqlist.add("Geeks");
absqlist.add("for");
absqlist.add("Geeks");
absqlist.add("10");
absqlist.add("20");
// Output the list
System.out.println("AbstractSequentialList:"
+ absqlist);
// Remove the head using remove()
absqlist.remove(3);
// Print the final list
System.out.println("Final List:"
+ absqlist);
}
}
輸出:
AbstractSequentialList:[Geeks, for, Geeks, 10, 20] Final List:[Geeks, for, Geeks, 20]
程序2:
// Java code to illustrate remove()
// with position of element passed as parameter
import java.util.*;
import java.util.AbstractSequentialList;
public class AbstractSequentialListDemo {
public static void main(String args[])
{
// Creating an empty AbstractSequentialList
AbstractSequentialList<String>
absqlist = new LinkedList<String>();
// Use add() method to add elements in the list
absqlist.add("Geeks");
absqlist.add("for");
absqlist.add("Geeks");
absqlist.add("10");
absqlist.add("20");
// Output the list
System.out.println("AbstractSequentialList:"
+ absqlist);
// Remove the head using remove()
absqlist.remove(0);
// Print the final list
System.out.println("Final AbstractSequentialList:"
+ absqlist);
}
}
輸出:
AbstractSequentialList:[Geeks, for, Geeks, 10, 20] Final AbstractSequentialList:[for, Geeks, 10, 20]
相關用法
- Java AbstractSequentialList set()用法及代碼示例
- Java AbstractSequentialList get()用法及代碼示例
- Java AbstractSequentialList addAll()用法及代碼示例
- Java AbstractSequentialList用法及代碼示例
- Java AbstractSequentialList contains()用法及代碼示例
- Java Map remove()用法及代碼示例
- Java Set remove()用法及代碼示例
- Java AbstractSequentialList equals()用法及代碼示例
- Java AbstractSequentialList removeAll()用法及代碼示例
- Java AbstractSequentialList conatinsAll()用法及代碼示例
- Java AbstractSequentialList isEmpty()用法及代碼示例
- Java AbstractSequentialList size()用法及代碼示例
- Java AbstractSequentialList.subList()用法及代碼示例
- Java AbstractSequentialList toString()用法及代碼示例
- Java AbstractSequentialList set(int, Object)用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 AbstractSequentialList remove() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。