Java AbstractCollection 类的 size() 方法
size()AbstractCollection类的方法返回集合中元素的数量。Integer.MAX_VALUE如果集合中的元素总数超过Interger.MAX_VALUE,则该方法返回。
语法如下:
public abstract int size()
要在Java中使用AbstractCollection类,请导入以下包:
import java.util.AbstractCollection;
以下是size()在Java中实现AbstractCollection方法的示例:
示例
import java.util.ArrayList; import java.util.AbstractCollection; public class Demo { public static void main(String[] args) { AbstractCollection输出结果
AbstractCollection = [Laptop, Tablet, Mobile, E-Book Reader, SSD, HDD] Count of Elements in the AbstractCollection = 6 Collection after removing some 2 elements = [Laptop, Mobile, E-Book Reader, HDD] Count of Elements in the updated AbstractCollection = 4