Generic Array list ArrayList

Source: Internet
Author: User

Why use a generic array list instead of a normal array?

1, ordinary arrays will often occur too large to waste the situation

2, normal array cannot change the array dynamically

Basic concepts:

1. class----> generic class with type parameter

2, "generic type" is the type of the type parameter

Operations on a generic array list:

1, add the elements, the Add method, the default is added in the tail, change parameters can be inserted into the middle. Delete Element

2. Initialize the capacity (ensurecapacity or transfer the initial capacity to the constructor)

3. Reclaim Excess storage space (trimtosize)

4. Accessing the array element get (i)

5. Convert to Array ToArray (a)

6. You can use the foreach traversal ArrayList

7. Number of calculated elements size ()

How do I interact with raw ArrayList that do not use type parameters? I can't read it.

@SuppressWarning("unchecked")

Generic Array list ArrayList

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.