Java collection, generic simple summary

Source: Internet
Author: User

objects in 1.set are not repeated in the order they are loaded . repeat judgment: as long as the two objects equals equal to the line. ( to understand that, not repeating the error, but only one storage time, the output will only output one.) )

Data objects in 2.list are ordered and can be duplicated

1) array read fast change slow

This is implemented in the form of an array, read the time according to the pointer can be read quickly, but change the time to copy the different parts and create a new array, so it is more troublesome.

2) linked fast reading slow

3. Loop out the contents of the collection:

1) Iterator mode iteration: Create an iterator for each object itself, and then use an iterator to determine if there is a next, then output.

2) used for loop form after jdk1.4

for (int aaa:list1) {

System.out.println (AAA);

}

is to list1 the contents of the collection into the AAA, and then output . However, in addition to traversing the output of all the content, there is no other benefits, such as to delete a certain time can not be implemented, see not recommended to use this method.

4. Automatic boxing and unpacking: In the collection, add the object, but jdk1.4 can add the basic number directly after the

Type, but this involves packing and unpacking problems.

1) Boxing: The underlying data type is converted to an object type that is boxed, which is to load an object into the underlying data type.

2) Unpacking: The object is transformed into a basic data type.

5. Generics

1) Why generics are used: the type of the mounted collection is treated as object, thus losing the original actual type. Therefore, after extracting from the set, it needs transformation, low efficiency and easy to make mistakes.

2) Use generics: Define the object types in the collection while defining the collection.

3) Scope of use: the essence of generics is to parameterize data types, not just collections, but also other places. Those classes can be used generics, look at the API documentation, API documentation can be used.

Java collection, generic simple summary

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.