The collection Collection

1, in the Java Collection (actually an interface) inherited the collection Iterable interface, so there Iterator method.

2, some of the common methods set Collection:

        *****************************************************		
		boolean add(E e);	泛型写法

		boolean add(Object e);	// 添加元素
    *****************************************************		
		int size();		// 获取集合中元素的个数 
    *****************************************************		
		void clear();	// 清空集合 
    *****************************************************		
		boolean contains(Object o);	// 判断集合是否包含元素 o
    						// 底层调用了 equals 方法
    *****************************************************		
		boolean remove(Object o);	// 删除集合元素 o
    *****************************************************		
		boolean isEmpty();	// 判断集合是否为空
    *****************************************************
		Object[] toArray();// 将元素转换成数组   (使用较少)
    *****************************************************

3、Iterator iterator () // obtain iterator object

迭代器 3 种方法:

	- boolean hasNext();	// 如果还有元素可以迭代,返回true
	
	- E next(); 或者 Object next();		// 返回迭代的下一个元素
	
	- void remove();		// 删除集合中的某个元素(底层调用 equals 方法)

Acknowledgments: Thanks to [Hao] ju bin teacher!

Guess you like

Origin www.cnblogs.com/yerun/p/12641538.html