A collection of Java Learning Families 2

Source: Internet
Author: User

Collection System

A Data

    1. List Collection Storage data structure

<1> Stack Structure

Features: Advanced post-out

      

<2> Queue Structure

Features: Advanced First Out

<3> Array Structure

Features: Fast query, adding and deleting slow

      

<4> Linked list structure

Features: Delete quickly, query slow

      

Two List Interface

Java.util.List Interface (collection)extends Collection interface

features of the List interface:

Allow duplicate elements to be stored

is an ordered set (the order in which the elements are stored and the order in which they are taken out) 123 out 123

indexed, including some unique methods with indexes (there are three ways to traverse: iterators, enhanced for, normal for )

Unique methods with indexes:

    1. Add (int index, e e); add an element on the specified index
    2. E Remove (int index); removes and returns the element at the specified index
    3. E Set (index int, e e); modifies and returns an element on the specified index
    4. E get (int index); returns the element at the specified position in the list;

Attention:

When manipulating index methods, be sure to avoid index out of bounds exceptions

Indexoutofboundexception: index out of bounds exception, the collection will report

Stringindexoutofboundexception: String index out of bounds exception

Arrayindexoutofboundexception: Array index out-of-bounds exception

Three Arraylist<e> Collection

Characteristics:

The bottom is an array structure, query fast, and delete slowly;

Ordered collection

Allow storage of duplicate data

Four Vector Collection

Jdk1.0 appears, single thread, line Shuo complete

Five Linkedlist<e> Collection

Java.util.linkedlist<e> Collection implements List<e>

Characteristics:

The bottom is a doubly linked list structure, query slow, and delete quickly;

Access is ordered.

Allow repeating elements

LinkedList -specific methods:

Added method:

      1. void AddFirst (e e) inserts the specified element at the beginning of this list
      2. void push (e e) inserts an element at the beginning of this list. This method is equivalent to AddFirst (e e)
      1. void Addlist (e e) adds the specified element to the end of the list, equivalent to Add (e e);

method to delete:

      1. E Removefirst (); Remove and return the first element of this list
      2. E Removelast (); removes the last element from the returned list;
      3. E pop () removes and returns the first element of this list, which is equivalent to removefrist ()

Get the method:

      1. E GetLast (); gets the last element
      2. E getfrist (); gets the first element
      3. Boolean IsEmpty (); Determine if the list is empty

Six Set Set

Java.util.Set Interface (collection) extends Collection interface

features of the Set interface:

      1. Duplicate elements are not allowed
      2. no index, no normal for traversal

Seven Hashset<e>

Java.util.hashset<e> Set implements set interface

features of the Hashset<e> interface

      1. The underlying principle is a hash table (array + one-way list), query fast, and delete quickly
      2. Unordered collections, which can be stored in a sequence that is inconsistent with the order taken

Use Hashset<e> The only principle of storing elements: overriding the hashcode () method and the equals () method;

Use HashSet the Add method stores an element , the hashcode ()method is called automatically,and then the hash value of the elements in the collection is compared, and if there is no identical hash value, it is deposited. If the hash value has the same, then the equals () method is called, and the equality is determined, if the equality is not deposited, the unequal deposit

Eight Linkedhashset<e>

Java.util.LinkedHashSet Collection extends HashSet collection

Linkedhashset<e> Features:

      1. underlying principle: Hash table (array + unidirectional linked list)+ doubly linked list.
      2. A doubly linked list guarantees an orderly access to elements. But element requirements cannot be duplicated

Nine Hash value

is a decimal integer, with the operating system randomly given

You can use the method Hashcode in the object class to get the hash value

int hashcode () Returns the hash code value of the object;

Source:

public native int hashcode ();

Native: refers to a method implementation that invokes the local operating system

Ten Arraylist<e> methods for storing non-repeating elements in a collection:

    1. Boolean contains (Object O); method to determine whether the specified element is included
    2. will be ArrayList element traversal is added to the set collection
    3. Use the construction method of HashSet set ; HashSet (Collection <? extends e> c)

A collection of Java Learning Families 2

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.