Java Set. Add() method: adds an object to the set collection
•
Java
add(E e)
Example
public static void main(String[] args){ Set set = new HashSet(); //定义Set集合对象 set.add(new Date()); //向集合中添加日期对象 set.add("apple"); //向集合中添加对象 set.add("book"); set.add("apple"); set.add(new Integer(3)); int size = set.size(); //获取集合的大小 System.out.println("Set集合的大小为:"+size); //将集合大小输出 }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码