Java collection classes

Source: Internet
Author: User

All things in Java are objects, data is encapsulated into classes, classes create objects, and containers are similar to arrays that hold objects. The container has the following characteristics than the array: 1, the container length is variable, the array is fixed in the heap memory, and 2, the container can hold different types of objects, and the array element types should be indicated when they are created. Two points in the final analysis, the existence of an array must be allocated at the beginning of creation and cannot be changed.

Set as a tool, stored in the Java.util package. Its top-level features are encapsulated by the interface collection. The following is an example of its basic method (because the interface needs to override its methods after inheritance, so use the ArrayList class that implements the interface instead).

Import java.util.*;p Ublic class Demo1 {public static void-out (Object obj) {System.out.println (obj);} public static void Main (string[] args) {ArrayList Al = new ArrayList ();/* Add Data Method Add () */al.add ("Collection1"); Al.add (" Collection2 "), Al.add (" Collection3 "), Al.add (" Collection4 ");/* Delete element */al.remove (2);/* Set length */out (" Al.size: "+al.size ( );/* Set Element */out (AL);}}
Operation Result:
Al.size:3
[Collection1, Collection2, Collection4]
It is important to note that the collection does not hold all of the objects stored in the collection, but is a reference to the object, that is, the address.

Java collection classes

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.