Java AbstractSequentialList类的set()方法
set()的AbtstractSequentialList类的方法被用于在该列表与指定元件指定的位置,以取代元素。它返回被替换的元素。语法如下-
E set(int index, E element)
在此,索引是要替换的元素的索引。ele是要存储在指定位置的元素。
要使用Java中的AbstractSequentialList类,您需要导入以下包-
import java.util.AbstractSequentialList;
以下是set()在Java中实现AbstractSequentialList方法的示例-
示例
import java.util.LinkedList;
import java.util.AbstractSequentialList;
public class Demo {
public static void main(String[] args) {
AbstractSequentialList<Integer> absSequential = new LinkedList<>();
absSequential.add(250);
absSequential.add(320);
absSequential.add(400);
absSequential.add(550);
absSequential.add(600);
absSequential.add(700);
absSequential.add(900);
System.out.println("Elements in the AbstractSequentialList = "+absSequential);
System.out.println("Replaced = " + absSequential.set(4,650 ));
System.out.println("Updated AbstractSequentialList = "+absSequential);
}
}输出结果
Elements in the AbstractSequentialList = [250, 320, 400, 550, 600, 700, 900] Replaced = 600 Updated AbstractSequentialList = [250, 320, 400, 550, 650, 700, 900]
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短