Javase (16) Sub-class of list, generics, enhanced for loop, static import, variable parameters

Source: Internet
Author: User

Subclass of 1:list (master)

(1) Sub-class features of list

ArrayList:

The underlying data structure is a number of groups, check 迿 fast, and delete slowly

Thread insecure, high efficiency

Vector:

The underlying data structure is a number of groups, query fast, and delete slowly

Thread-safe, low-efficiency

LinkedList:

The underlying data knot PO is linked list, query slow, and delete quickly

Thread insecure, high efficiency

(2) Arraylist

A: There is no specific function to learn

B: Case

A:arraylist Store strings and traverse

B:arraylist Store custom objects and traverse

(3) Vector

A: Unique Features

A: Add:

public void addelement (E obj)--add ()

B: Get

Public E elementat (int index)--get ()

Public enumeration<e> elements ()--iterator ()

B: Case

A:vector store characters sit and traverse

B:vector Store custom objects and pass the calendar

(4) LinkedList

A: Has a unique function

A: Add

AddFirst ()

AddLast ()

B: Delete

Removefirst (

Removelast (

C: Get

GetFirst ()

GetLast ()

B: Case 9 Tlast (

A:linkedlist Store strings and traverse

B:linkedlist Store custom objects and traverse

(5) Case:

A: Removing duplicate elements from multiple strings in a collection

If the contents of the string are the same, the repeating element is turbulent

B: Remove duplicate elements from multiple custom objects in the collection

If the value of the member variable for the custom object is the same, the repeating element is turbulent

C: Use LinkedList to simulate the collection class of a stack data structure and test it.

You want to define a collection class, but you can use LinkedList to implement it internally.

2: Generics (Master)

(1) Generic overview

is a special type of explicit type that is deferred until the object is created or the method is called.

(2) format

< data types >

Note: This data type can only be reference type a

(3) Benefits

A: Advance the run-time problem to the compile period

B: Forced type conversions are avoided

C: Optimization of the program design, the solution of the yellow warning line problem, so that the program more Xuan full

(4) Generics of past life

A: The origin of generics

When an object type is an arbitrary type, a transformation problem is implied when the transition is down.

B: Generic class

C: Generic method

D: Generic interface

E: Generic high-level wildcard character

?

? Extends E

? Super E

(5) Where do we use it?

is used in the collection.

3: Enhanced for loop (master)

(1) is a For loop

(2) format

For (the element's data type variable name: An array or an object of the collection collection) {

With this variable, the variable is actually the element in the set of number of members

}

(3) Benefits

Simplifies the traversal of arrays and collections

(4) Disadvantages

The target of the enhanced for loop cannot be nu11, and it is recommended to determine whether it is nu1l before use.

4: Static import (Learn)

(1) Import to method level can be imported

(2) Format:

Import static Package name ... Class name. method name;

(3) Precautions

A: The method must be static

B: If more than one class has a method with the same name, it is not good to differentiate, but also to add a prefix

So generally we do not use static import, but we must be able to read

5: Variable parameters (Master)

(1) If we are writing a method, the parameter number is ambiguous, we should define the variable parameter

(2) Format:

Cestoda Charm return value type method name (data type ... Variable) {}

Attention:

A: The variable is actually an array name

B: If a method has more than one parameter and has a mutable parameter, the variable parameter must be in the last

(3) A method of arrays tool class

Aslist () turns the array into a set

Note: The length of this collection cannot be changed

Javase (16) Sub-class of list, generics, enhanced for loop, static import, variable parameters

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.