Java Basic Knowledge Enhancement Collection Framework note 03:collection Collection features overview

Source: Internet
Author: User

1. Collection Features Overview:
Collection is the top-level interface of a set, and its sub-systems are repetitive, unique, orderly, unordered.

(1) Add function

1 Boolean Add   (Object  obj): Adds an element 2boolean  AddAll (Collection C): Adds an element of a collection

(2) Delete function

1 void Clear (): Remove all elements

(3) Judgment function

1 Boolean   contains (Object  obj): Determines whether the collection contains the specified element 2boolean  containsall (Collection C): Determines whether the collection contains the specified collection element 3boolean  isEmpty (): Determines whether the collection is empty

(4) Get function

1 iterator<e>  Iterator ()  (emphasis)

(5) Length function

1 int  Size (): The number of collection elements

The Length property in Java is said for an array , for example, you declare an array, and you want to know how long this array is to use this property.
• the length () method in Java is for string literals , and the length () method is used if you want to see how long the string is.
• the size () method in Java is said for a generic collection , and if you want to see how many elements of the generic, call this method to view it!
This example demonstrates the use of both methods and a property

1  Public Static voidMain (string[] args) {2String []list={"Ma", "Cao", "Yuan"};3String a= "Macaoyuan";4 System.out.println (list.length);5 System.out.println (A.length ());6List<object> array=NewArrayList ();7 Array.add (a);8 System.out.println (Array.size ());9}

The output value is:

391

(6) Intersection function

1 boolean retainall (Collection  C): intersection of two sets

(7) Convert the set into an array

1 object[]  ToArray ()

Java Basic Knowledge Enhancement Collection Framework note 03:collection Collection features overview

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.