The specified behavior of underlying Object methods wherever the The various Collections Framework interfaces are free to take advantage of Unequal hash codes cannot be equal.) More generally, implementations of Object.hashCode() specification guarantees that two objects with Optimizations whereby the equals invocation is avoided, forĮxample, by first comparing the hash codes of the two elements. With a non-null argument o will cause o.equals(e) to be Not be construed to imply that invoking ntains (o=null ? e=null : o.equals(e))." This specification should Method says: "returns true if and only if this collectionĬontains at least one element e such that The specification for the contains(Object o) Many methods in Collections Framework interfaces are defined in Thread this includes direct invocations, passing the collection toĪ method that might perform invocations, and using an existing Of any method on a collection that is being mutated by another Implementation, undefined behavior may result from the invocation In the absence of a stronger guarantee by the It is up to each collection to determine its own synchronization Such exceptions are marked as "optional" in the specification for this The insertion of an ineligible element into the collection may throw anĮxception or it may succeed, at the option of the implementation. Operation on an ineligible element whose completion would not result in Or it may simply return false some implementations will exhibit the formerīehavior and some will exhibit the latter. To query the presence of an ineligible element may throw an exception, NullPointerException or ClassCastException. Attempting toĪdd an ineligible element throws an unchecked exception, typically For example, some implementations prohibit null elements,Īnd some have restrictions on the types of their elements. Some collection implementations have restrictions on the elements that The addAll(Collection) method on an unmodifiable collection may,īut is not required to, throw the exception if the collection to be added Invocation would have no effect on the collection. Required to, throw an UnsupportedOperationException if the If this is the case, these methods may, but are not Throw UnsupportedOperationException if this collection does not Methods that modify the collection on which they operate, are specified to The "destructive" methods contained in this interface, that is, the Implementations in the Java platform libraries comply. There is no way to enforce this convention (as interfaces cannot containĬonstructors) but all of the general-purpose Collection Producing an equivalent collection of the desired implementation type. InĮffect, the latter constructor allows the user to copy any collection, Subinterfaces) should provide two "standard" constructors: a void (noĪrguments) constructor, which creates an empty collection, and aĬonstructor with a single argument of type Collection, whichĬreates a new collection with the same elements as its argument. Typically implement Collection indirectly through one of its Is typically used to pass collections around and manipulate them whereīags or multisets (unordered collections that may containĭuplicate elements) should implement this interface directly.Īll general-purpose Collection implementation classes (which Specific subinterfaces like Set and List. Implementations of this interface: it provides implementations of more SomeĬollections allow duplicate elements and others do not. Represents a group of objects, known as its elements. The root interface in the collection hierarchy.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |