White Tour 14

A. Collection

  • Collection
    • List Interface
      • ArrayList
      • LinkedList
      • Vector
    • Set Interface
      • HashSet
      • TreeSet
      • LinkedHashSet

Collection interface is a set of ancestors frame

Collections set of operating tools

A set of different data structures vary, resulting in a set of performance efficiency of the operation is also different.

List: orderly and repeatable

Set: disorderly and not repeat

Can only store a reference set of data types, the basic data types can not be stored

二. ArrayList

2.1 Create

format:

ArrayList <data type> set name = new ArrayList <> ();

2.2 common method

1, add (e): adding e to the end of the collection, whether to add a successful return a Boolean value, list of add function may only return true

2, add (index, e): adding the specified location to the set of e

3, remove (index): delete the element at the specified location, return the removed element

4, remove (obj): Remove the first element obj, returns a Boolean value is successfully deleted

5, set (indexl, e): e replacing the elements on the index position, and returns the replaced element

6, get (index): Gets the element at the specified location

7, size (): Get the length of the collection

8, isEmpty (): determines whether the set is empty

9, contains (e): determining whether there is a specified element

10, indexOf (e): acquiring location specified element

11, lastIndexOf (): Gets the specified element location

12, a.addAll (b): The b set to the end of a set of

13, a.addAll (index, b): The b set to the specified position of a set of

14, a.containsAll (b): a determination whether the collection contains all the elements of the set b

15, a.retainAll (b): The a, b intersection of the sets assigned to a collection and returns a collection of whether been altered

16, a.removeAll (b): remove a from a set, the set intersection of element b

Nested set 2.3

2.4 as a set of parameter and return type

Three. LinkedList

List LinkedList and ArrayList are implementation class, have the same functionality as the data of the CRUD.

The LinkedList a few more features, such as: push (), pop (), poll (), peek () and so on.

Because different data structures and ArrayList LinkedList underlying

ArrayList data structure is an array, LinkedList data structure is a linked list.

ArrayList: Find fast, slow additions and deletions

LinkedList: additions and deletions fast, slow look

Guess you like

Origin www.cnblogs.com/demonycw/p/11329365.html