contains()
AbstractSequentialList的在Java方法被用来检查一个元素是否在Collection。
语法如下
public boolean contains(Object ob)
在这里,ob是要检查的元素。要使用Java中的AbstractSequentialList类,您需要导入以下包
import java.util.AbstractSequentialList;
以下是contains()
在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("Does the element exist? = " + absSequential.contains(400)); } }
输出结果
Elements in the AbstractSequentialList = [250, 320, 400, 550, 600, 700, 900] Does the element exist? = true