当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java AbstractSequentialList remove()用法及代码示例


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]


相关用法


注:本文由纯净天空筛选整理自Chinmoy Lenka大神的英文原创作品 AbstractSequentialList remove() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。