One, Javase (15) Object array, collection (Collection), collection (List)

Source: Internet
Author: User

1: Object Array ( master )

(1) arrays can store both basic data types , You can also store reference types. It is called an array of objects when it stores the reference type.

(2) Case :

Stores 5 student Objects in an array , and iterates through the array.

2: Collection (Collection) ( master )

(1) The origin of the collection ?

We are learning java-- Object-oriented -- manipulating many objects - - storage -- containers ( arrays and stringbuffer)-- Arrays

While the length of the array is fixed , so it is not suitable for changing requirements , Java provides a collection for us to use

(2) the difference between a collection and an array ?

A: Length Difference

Array pinning

Set Variable

B: Content Differences

An array can be a base type , or it can be a reference type

Collections can only be reference types

C: element Content

Arrays can only store the same type

Collections can store different types ( In fact, collections typically store the same type )

(3) Inheritance architecture for collections ?

Because of the different requirements , Java provides different collection classes. The data structure of these multiple collection classes is different , But they are all to provide storage and pass-through functions ,

We extract the generality of them continuously , and finally form the inheritance architecture of the set .

Collection

|--list

|--arraylist

|--vector

|--linkedlist

|--set

|--hashset

|--treeset

(4) Collection Overview of features (self- completed )

A: Add features

B: Remove Features

C: Judging function

D: Get features

E: length function

F: intersection ( learn )

G: Turn the set to a number ( learn )

(5) Collection the pass calendar of the collection

A: Turn the set to a number ( learn )

B: iterators (Collection- specific method )

(6) iterators

A: is the way the collection gets the elements

B: is a collection-dependent existence.

C: the principle and source of the iterator

A: why define for an interface instead of implementing a class ?

B: look at the inner class implementation of the iterator .

(7) Collection Collection of cases (Traversal- mode iterator )

Procedure for collection:

A: Create a collection

B: Creating an Element object

C: adding elements to the collection

D: iterating through the collection

A: store characters and pass the calendar

B: Store custom objects and traverse

3: Collection (List) ( master )

(1) List is a co11ection the sub-interface

features : ordered ( same order of storage and removal ), repeatable ;

(2) List Unique features of :( Self -completion )

A: Add features

B: Remove Features

C: Get features

D: iterator Capabilities

E: Modifying features

(3) List unique traversal capabilities for collections

A: by size () and the get () combined

(4) Unique features of list iterators :( Understand )

It can be traversed in reverse , but it must be traversed first , so it makes no sense , basically does not use

(5) Concurrency Modification Exceptions

A: phenomena that occur

iterators iterate through collections , Collections Modify collection Elements

B: cause

The transmitter is dependent on the collection , and the set of changes to the surrogate does not know

C: Solution Solutions

A: Iterator Event Calendar , Iterator Modification (Listiterator)

element is added at the location of the iteration just

B: Collection Pass Calendar , Collection Modification (Size () and get ())

element is added to the end of the collection

(6) Common data Structures

A: Stack Advanced post-out

B: Queue Advanced First Out

C: Array Query Fast , Delete Slow

D: Linked list Slow Query , Quick and Delete

(7) Five is T sub-class characteristics ( face Test )

Arraylist

the underlying data structure is a number of groups , query Fast , and Delete slowly

thread insecure , High efficiency

Vector

the underlying data structure is an array , query Fast , and Delete steamed bread

Thread-safe , low-efficiency

LinkedList

the underlying data structure is linked list , query slow , Delete quickly

thread insecure , high efficiency A

who do you use it for ? See demand ?

Analysis :

Are you safe ?

to : Vector ( Even if you want to , do not use this , after the /c13>)

do not : Arraylist or linkedlist

Query more : Arraylist

More additions and deletions : LinkedList

don't know anything , just use Arraylist .

One, Javase (15) Object array, collection (Collection), collection (List)

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.