Why do we use List and set (List,set)

Source: Internet
Author: User

1. Overview of the collection

Class diagram

The difference between sets and arrays.

Set Basic methods

Collection-specific traversal method.
                public static void Main (string[] args) {
                    //Create collection Object
                    Collection c = new ArrayList ();

                    Create and add element
                    c.add ("Hello");
                    C.add ("World");
                    C.add ("Java");

                    Traversal collection
                    Iterator it = C.iterator ();
                    while (It.hasnext ()) {
                        string s = (String) it.next ();
                        System.out.println (s);
                    }
                
2, List and set Overview
List and set differences.

3, List

List features and implementation classes

For knowledge of thread safety, refer to http://blog.csdn.net/qq_34149805/article/details/64128499

For the knowledge of the linked list, refer to http://blog.csdn.net/qq_34149805/article/details/67117288 4, Set

Set features

The set has exactly the same interface as collection, so there is no additional functionality, unlike the two different lists that preceded it. In fact set is collection, but behavior is different. (This is a typical application of inheritance and polymorphic thinking: behavior that behaves differently.) Set does not save duplicate elements (more responsible for determining the same element)

Each element of a set stored in a set must be unique because the set does not save repeating elements. Elements that join a set must define the Equals () method to ensure the uniqueness of the object. Set has exactly the same interface as collection. The set interface does not guarantee the order of elements to be maintained.

Set Implementation class

5, Summary

Data
ARRAYXXX: The underlying data structure is an array, query fast, additions and deletions slow

linkedxxx: The underlying data structure is linked list, query slow, additions and deletions quickly

hashxxx: the underlying data structure is a hash table. Relies on two methods: Hashcode () and Equals ()

treexxx: The underlying data structure is a two-fork tree. Sort in two ways: natural sort and comparer sort
Why we use them.

RELATED LINKS Java Map Super verbose rollup

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.