Java Collection Collection Interface

Source: Internet
Author: User

The collection interface is the basis of the set-up framework. It declares the core method of all collections. These methods are summarized in the following table.

Because all collections are implemented collection, it is necessary to be familiar with it by having a clear understanding of the framework. There are several ways to throw a unsupportedoperationexception.

SN Method and Description
1 boolean Add (Object obj)
Adds obj to the call collection. Returns true if obj is added to the collection. Returns False if obj is already a member of the collection or if the collection does not allow duplicates.
2 Boolean AddAll (Collection c)
Added all elements of C to the call collection. Returns true if the operation succeeds (that is, the element being added). Otherwise, returns false.
3 void Clear ()
Removes all the elements in the call collection.
4 Boolean contains (Object obj)
Returns True if obj is an element in the calling collection. Otherwise, returns false.
5 Boolean containsall (Collection c)
Returns true if all elements in the call collection contain C. Otherwise, returns false.
6 Boolean equals (Object obj)
Returns True if the calling collection is equal to obj. Otherwise, returns false.
7 int Hashcode ()
Returns the hash code of the calling collection.
8 Boolean IsEmpty ()
Returns True if the calling collection is empty. Otherwise, returns false.
9 Iterator Iterator ()
Returns a collection of calls to an iterator.
10 Boolean remove (Object obj)
Removes an instance of obj from the call collection. Returns True if the element is deleted. Otherwise, returns false.
11 Boolean RemoveAll (Collection c)
Removes all elements from the call collection C. Returns True if the collection changes (that is, the element being deleted). Otherwise, returns false.
12 Boolean retainall (Collection c)
Removes the call collection, except for all elements that are in C. Returns True if the collection changes (that is, the element being deleted). Otherwise, returns false
13 int size ()
Returns the number of elements held by the call collection.
14 Object[] ToArray ()
Returns an array that contains all the elements stored in the calling collection. An array element is a copy of an element collection.
15 Object[] ToArray (Object array[])
Returns an array of type-matching arrays that contain only those element collections.
Example:

Here is an example of how to implement some methods from the different classes of the above collection methods:

 ArrayList Elements        [Zara, Mahnaz, Ayan] LinkedList Elements [Zara, Mahnaz, Ayan] Set Elements [Zara, Mahnaz, Ayan] Map Elements {Mahnaz=31, Ayan=12, daisy=14, zara=8       


Java Collection Collection Interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.