Java 中 AbstractSequentialList 的 equals() 方法
equals() 方法从 Java 中的 AbstractList 类中继承。它用于检查对象是否与该列表相等。如果对象等于该列表,则返回 TRUE,否则返回 FALSE。
语法如下所示 -
public boolean equals(Object o)
其中,o 是要与该列表进行比较以确定是否相等的对象。
要在 Java 中使用 AbstractSequentialList 类,需要导入以下包
import java.util.AbstractSequentialList;
以下是实现 Java 中 AbstractSequentialList equals() 方法的示例
示例
import java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo { public static void main(String[] args) { AbstractSequentialList<Integer> absSequential1 = new LinkedList<>(); absSequential1.add(110); absSequential1.add(320); absSequential1.add(400); absSequential1.add(550); absSequential1.add(600); absSequential1.add(700); absSequential1.add(900); System.out.println("Elements in the AbstractSequentialList1 = "+absSequential1); AbstractSequentialList<Integer> absSequential2 = new LinkedList<>(); absSequential2.add(110); absSequential2.add(320); absSequential2.add(400); absSequential2.add(550); absSequential2.add(600); absSequential2.add(700); absSequential2.add(900); System.out.println("Elements in the AbstractSequentialList2 = "+absSequential2); System.out.println("Both the AbstractSequentialList2 equals? "+ absSequential1.equals(absSequential2)); } }
输出
Elements in the AbstractSequentialList1 = [110, 320, 400, 550, 600, 700, 900] Elements in the AbstractSequentialList2 = [110, 320, 400, 550, 600, 700, 900] Both the AbstractSequentialList2 equals? True
广告