Java BASICS (15th) Set (2), java basics set

Source: Internet
Author: User

Java BASICS (15th) Set (2), java basics set

Here are some of the knowledge points and code I summarized in my previous class. Most of the notes I think are very good and classic, sincerely hope that these will help those who want to learn!

It is inconvenient to upload code by module. There are also many things, and they are also clear! If you need it, you can leave your email in the comments. I will certainly send it to you for free! Thank you for making progress on this platform !! Remember that programmers are selfless !!!

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

 

/* 1: sub-class of List (master) (1) Sub-class features of List ArrayList: the underlying data structure is an array, which is fast in query, and is not safe for threads with slow addition, deletion, and high in efficiency. Vector: the underlying data structure is an array, which provides fast query, secure thread adding and deletion, and low efficiency. Slow list: the underlying data structure is a linked list. Slow query, unsafe thread adding and deletion, and high efficiency (2) arrayList A: No features available. B: Case a: ArrayList: store strings and traverse B: ArrayList: store custom objects and traverse (3) Vector A: features: add public void addElement (E obj) -- add () B: get public E elementAt (int index) -- get () public Enumeration <E> elements () -- iterator () B: case a: Vector stores strings and traverses B: Vector storage Custom object and traverse (4) topology List A: special function a: Add addFirst () addLast () B: delete removeFirst () removeLast () c: Get getFirst () getLast () B: Case a: Using list to store strings and traverse B: Using list to store custom objects and traversing (5) case:: remove repeated elements from multiple strings in the set. If the content of the string is the same, duplicate Element B: remove repeated elements of multiple custom objects in the set. If the value of member variables of the custom object is the same, that is, repeated element C: Use the repeated list to simulate a collection class of stack data structure, and test. You need to define a collection class, but you can use the collections list internally. 2: Generic (GRASP) (1) Generic overview is a special type that delays explicit types of work until an object is created or a method is called. (2) Format: <data type> note: the data type can only be a reference type. (3) Benefits: A: Advance the problem during the running period to the compilation period B: avoids forced type conversion C: optimizes the program design and solves the yellow warning line problem, making programs safer (4) Generic past and present A: When the generic source Object type is any type, A transformation problem B will be hidden during the downward Transformation: generic class C: Generic method D: generic interface E: Generic high-level wildcard?? Extends E? Super E (5) where can we use it? It is generally used in a collection. 3: Enhanced for loop (GRASP) (1) is a for loop (2) Format: for (element data type variable name: array or Collection set object) {use this variable. The variable is actually an array or an element in the set.} (3) Benefits: simplifies the traversal of arrays and sets (4) Disadvantages: the target of the for Loop cannot be null. We recommend that you determine whether the value is null before use. 4: static import (understanding) (1) method-level import (2) Format: import static package name .... class Name. method Name; (3) Note: A: The method must be static B. If multiple classes have methods of the same name, it is difficult to distinguish them, and A prefix must be added. So we generally do not use static import, but we must be able to understand it. 5: variable parameters (master) (1) if the number of parameters in the write method is ambiguous, variable parameters should be defined. (2) Format: modifier return value type method name (data type... variable) {} Note: A: This variable is actually an array name B: If A method has multiple parameters and there are variable parameters, variable parameters must be at the end (3) an asList () method of the Arrays tool class converts an array into a set. Note: the length of the set cannot be changed. 6: Exercise (master) A: Nested traversal of the Set B: generate A random number between 10 and 20. the random number must not be repeated. C: enter multiple data on the keyboard and end with 0, and output the maximum value 7 in the console: The storage elements of the Code set to be mastered, add the generic type, and use enhanced for traversal. *\

 

Related Article

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.