Collection Interface Overview
The root interface in the Collection hierarchy. Collection represents a set of objects, also known as Collection elements. Some collection allow duplicate elements, while others do not. Some of the collection are orderly, while others are unordered.
Boolean Add (E E)
Boolean remove (Object o)
void Clear ()
Boolean contains (Object o)
Boolean IsEmpty ()
int size ()
Write a test class below to test the method above
Package Cn.itcast_01;import Java.util.arraylist;import java.util.Collection;
Public class collectiondemo { public static void main (String[] args) { // test methods without all // create a collection object // collection c = new collection (); //error because interface is not instantiated Collection c = new ArrayList (); // boolean add (object obj): Add an element // system.out.println ("Add:" +c.add ("Hello")); c.add ("Hello"); c.add ("World"); c.add ("Java"); // void clear (): Remove all elements // c.clear (); // boolean remove ( Object o): Removes an element // system.out.println ("Remove:" + c.remove ("Hello")); // system.out.println ("Remove:" + c.remove ("Java ee"));(delete elements not in the original collection, return False, the elements of the collection are not changed, No effect on the original set) // boolean contains (Object o): Determines whether the collection contains the specified element // System.out.println ("contains:" +c.contains("Hello")); // system.out.println ("contains:" +c.contains ("Android")); // boolean IsEmpty (): Determines whether the collection is empty // system.out.println ("IsEmpty:" +c.isempty ()); //int size () : The number of elements system.out.println ("Size:" +c.size ()); system.out.println ("C:" +  C); }}
Use Notepad to practice, compile the time will report the following such a problem
Note: Collectionxxx.java is using an unchecked or unsafe operation.
Note: To learn more, recompile with-xlint:unchecked. (This is not a compilation failure, not an error!) Knowledge may be an error! )
The Java compiler believes the program has a security risk
Warm tip: This is not a compilation failure, so first ignore, and so learn generics you know
ArrayList this set element can always be successful (because the last sentence of its add source is return true), so it can be said that ArrayList this collection is a repeatable collection
Adding and deleting methods to directly move the set, judging the fixed set
This article from "GD" blog, reproduced please contact the author!
Collection Framework (Basic functional testing of the collection collection)