-
- Java Api--java.util.collection Interface
-
/** * @author Chen * @date 20170317 * @description: This program tells Collection interface * java.util.Collection * Overview: Collection interface is the parent interface of the Set and list interface, Co The Llection interface defines a number of methods that are used for collection element operations, inherited by the implementation class of its sub-interfaces and sub-interfaces * Constructors * Java interfaces cannot have constructors * member functions: * "1" Overview, because collection is actually an interface, so the functions described below have no function body, that is, their function body is empty * "2" int size ();//Returns the number of elements in the collection, if the number of elements >in Teger. Max_value, then the return value of the function ==integer.max_value * "3" Boolean isEmpty ();//Whether the collection is empty * "4" Boolean contains (objec t o);//Whether the collection contains elements O:object * "5" iterator<e> Iterator ();//Returns an iterator (that is, Iterator object) that can traverse all the elements in the collection * " 6 "object[] ToArray ();//Convert the set into an array *" 7 "<T> t[] ToArray (t[] a);//This function is similar to the function given in" 6 ", but this function has additional functions * Function: This function transforms the collection element data type to the array element data type except the set transformation (the parameter of the cost function is transformed by the collection element from the original data type a:t[] Data type represented--T) * Additionally, the length of the function return value is specified (the length of the return value is consistent with the length of the parameter array of this function a:t[]) * @return The contents of the return value (array)--the data type of the array element in the return value--consistent with the parameter data type of the function * return value (array) length--and this letter The length of the parameter array of the number is consistent, when the number of collection elements is less than the parameter array a:t[] length, null fills the empty space so that the return value length reaches the required * "8" Boolean Add (e e);//Add a new element to the collection * "9" bo Olean Remove (Object o);//delete an element from the collection * "10" Boolean Containsall (collection<?> c);//Determine if the collection contains all the elements in the parameter collection * "11" Boolean AddAll (collection<? extends e> c);//Add all elements from the parameter collection to the collection (equivalent to the set) * "12" Boolean RE Moveall (collection<?> c);//After this function executes, the collection will no longer contain any one of the elements in the parameter collection (equivalent to the set subtraction) * "13" Boolean Retainall (collection< ;? > C);//After executing this function, the collection will not be able to contain elements that do not exist in the parameter collection (equivalent to fetch intersection) * "14" void clear ();//After executing the function, the collection becomes empty * "15" Boolea n Equals (Object o);//Parameter O:object is also a collection, this function is used to determine whether the contents of two sets are the same * "16" int hashcode ();//returns the hashcode code corresponding to the collection * Note: If the contents of the two collections are identical, then the hashcode codes for the two collections must be identical * i.e., if a.equals (b) ==true, then there must be A.hashcode () ==b. Hashcode () **/ Packagejava_api_dataStructure.Collection.List.ArrayList;Importjava.util.ArrayList;Importjava.util.Collection;ImportJava.util.Iterator; Public classjavaapi_collection { Public Static voidMain (string[] args) {Collection Collection=NewArrayList (); }}
/** * @author chen * @date 20170317 * @description: This procedure tells Collection interface * Java.util.Collection * Overview: The collection interface is the parent interface of the set and list interfaces, and the collection interface defines some * methods for collection element operations, inherited * constructors by their sub-interfaces and the implementation classes of sub-interfaces * Interfaces in Java cannot have constructors * member functions: * "1" Overview, because collection is actually an interface, so the functions described below have no function body, that is, their function body is empty * "2" int size (); /returns the number of elements in the set, if the number of elements >integer.max_value, then the return value of the function ==integer.max_value * "3" Boolean isEmpty ();//Whether the collection is empty * " 4 "Boolean contains (Object o);//Whether the collection contains elements o:object *" 5 "iterator<e> Iterator ();// Returns an iterator that iterates through all the elements in the collection (that is, the iterator object) * "6" object[] ToArray ();//Transforms the collection into an array * "7" <T> t[] ToArray (t[] a); /This function is similar to the function given in "6", but this function has an additional function * function: This function, in addition to converting the collection to an array of *, also implements the collection element data type to Conversion of the array element data type (the data type represented by the parameter a:t[] of the cost function that transforms the collection element from the original data type--T) * In addition, the length of the return value of the function (the length of the return value and the length of the parameter array a:t[] of the function is consistent) * Returns the contents of the return value (array)-The data type of the array element in the return value of the collection element-- * The parameter data type of the function * the length of the return value (array)--consistent with the length of the parameter array of this function, when the number of collection elements is less than the parameter array a:t[] Length, use NULL to fill the empty space so that the return value length reaches the required * "8" bOolean Add (e e);//Adds a new element to the collection * "9" boolean remove (Object o);//Removes an element from the collection * "10" Boolean Containsall (Collection <?> c);//Determines whether the collection contains all elements in the parameter collection * "11" Boolean AddAll (collection<? extends e> c);// Adds all the elements in the parameter collection to the collection (the equivalent of the fetch set) * "12" Boolean RemoveAll (collection<?> c);//After this function is executed, The collection will no longer contain any one of the elements in the parameter collection (equivalent to set subtraction) * "13" Boolean Retainall (collection<?> c);//After executing this function, The collection will not be able to contain elements that do not exist in the parameter collection (equivalent to fetch intersection) * "14" void clear ();//After executing the function, the collection becomes empty * "15" Boolean Equals (Object o);//Parameter O:o Bject is also a collection, this function is used to determine whether the contents of two sets are the same * "16" int hashcode ();//returns the hashcode code corresponding to the set * Note: If the contents of the two collection are identical, Then the two sets corresponding to the Hashcode code must also be the same * that is, if A.equals (b) ==true, then there must be A.hashcode () ==b.hashcode () * */package Java_api_ DataStructure.Collection.List.ArrayList;
Import Java.util.arraylist;import Java.util.collection;import java.util.Iterator;
public class Javaapi_collection {public static void main (string[] args) {Collection collection=new ArrayList ();}
}
Java----data structure and algorithm----JavaAPI:java.util.Collection interface