Java Fundamentals (14) set (i)

Source: Internet
Author: User

Here are some of the lessons I summarized in the previous lesson and the code is most of the teacher's notes personally think is very good, but also a more classic content, sincere hope that these for those who want to learn some help!

Because the code is sub-module upload is very inconvenient. Also more, speak of is more clear! If you need to be able to leave your email in the comments I see will be sent to you for free! Thank you for this platform let us all progress together!! Remember that the programmer is selfless!!!

Also very welcome to my blog to watch the blog address: http://www.cnblogs.com/duscl/

/*1: Array of objects (mastering) (1) arrays can store either the base data type or the reference type.    It is called an array of objects when it stores reference types. (2) Case: Store 5 student objects in an array and iterate over the array.        2: Collection (Collection) (mastering) (1) The origin of the collection?    We are learning Java-object-oriented-manipulating many objects--storing--containers (arrays and StringBuffer)--arrays whose lengths are fixed, so it is not suitable for changing requirements, and Java provides a collection for us to use.        (2) What is the difference between a set and an array?            A: Length difference array fixed set variable B: Content difference array can be base type or reference type collection can be reference type C: element content        An array can store only the same type of collection that stores the inheritance architecture of a collection of different types (in fact, the same type that the collection typically stores) (3)? 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 traversal function, we take their generality upward extraction, and finally formed a collection of inheritance architecture diagram.            Collection |--list |--arraylist |--vector |--linkedlist        |--set |--hashset |--treeset (4) Collection function overview (self-completion) A: Add feature B: Remove feature C: Judgment function D: Get function E: Length function F: intersection (understanding) G: Turn the set into an array (understanding) (5) Traversal of the collection collection A: Turn the set into an array (learn) B    : Iterator (Collection-specific) (6) Iterator A: Is the way the collection gets the elements.    B: It is dependent on the collection and exists.            C: The principle and source of the iterator.            A: Why is the definition for an interface instead of an implementation class?    B: Look at the inner class implementation of the iterator. (7)            Collection steps for a collection of cases (traversal mode iterators) Set: A: Creating a Collection Object B: Creating an Element Object C: Adding elements to the collection D: Traversing the collection            A: Store strings and traverse import java.util.Collection;            Import java.util.ArrayList;                        Import Java.util.Iterator;                    public class Collectiondemo {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);            }                }            }    B: Store the custom object and traverse public class Student {private String name;                                private int age; Public Student () {} public Student (String Name,int age) {this.name = Nam                    E                This.age = age;            }//getxxx ()/setxxx ()} import java.util.Collection;            Import java.util.ArrayList;                        Import Java.util.Iterator;                    public class Studentdemo {public static void main (string[] args) {//Create collection Object                                        Collection C = new ArrayList ();                    Create student object Student S1 = new Student ("Brigitte", 27);                    Student s2 = new Student ("Wind Qingyang", 30);                    Student s3 = new Student ("Elina", 30);                    Student S4 = new Student ("Wu Xin", 25); Student S5 = New Student ("Lynn Qu", 16);                    add element C.add (S1);                    C.add (S2);                    C.add (S3);                    C.add (S4);                                        C.add (S5);                    Traversal collection Iterator it = C.iterator ();                        while (It.hasnext ()) {Student s = (Student) it.next ();                    System.out.println (S.getname () + "---" +s.getage ());    }}}3: Collection (list) (master) (1) The List is a sub-interface feature of the collection: ordered (in accordance with the order of storage and fetch), repeatable. (2) Unique features of list: (self-made) A: Add function B: Remove function C: Get function D: iterator function E: Modify function (3) Unique traversal function for list set a: by size        () and get () combined.                                        B: Code demo//Create collection Object List List = new ArrayList ();                    Create and add element List.add ("Hello");                    List.add ("World");   List.add ("Java");                                     Traversal collection Iterator it = List.iterator ();                        while (It.hasnext ()) {String s = (string) it.next ();                    System.out.println (s);                                        } System.out.println ("----------");                        for (int x=0; x<list.size (); x + +) {string s = (string) list.get (x);                    System.out.println (s);    } (4) The unique function of the list iterator, (understanding) can be traversed backwards, but first forward traversal, so meaningless, basically not used.        (5) Concurrency modification exception A: The occurrence of a phenomenon iterator iterates through the collection, the collection modifies the collection element B: The cause iterator is dependent on the collection, and the collection's change iterator does not know.                C: Solution A: iterator traversal, iterator modification (listiterator) element added in the position of just iteration B: Collection traversal, collection modification (size () and get ())        Element added at the end of the collection (6) Common data structure A: stack advanced after the B: Queue FIFO C: Array query fast, add and subtract slow D: List of slow, add and delete fast (7) List of sub-class characteristics (interview questions)            ArrayList the underlying data structure is an array, query fast, and delete slowly.        Threads are unsafe and highly efficient. VecTor the underlying data structure is an array, query fast, and delete slowly.        Thread-safe, low-efficiency.            LinkedList the underlying data structure is linked list, query slow, delete quickly.                    Threads are unsafe and highly efficient.        Who do you use? Look at the demand?                Analysis: Is it safe? To: Vector (even if you want, do not use this, and later) do not: ArrayList or linkedlist query more; ArrayList and more:    LinkedList don't know anything, just use ArrayList. (8) List collection cases (traversal mode iterator and normal for) A: Store Strings and traverse B: Store custom objects and traverse *\

Java Fundamentals (14) set (i)

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.