5.02_List collection

First, remove the string elements repeated manner ArrayList
  * A: Case presentation
    * demand: ArrayList remove duplicate set of values in a string (a string of the same content)
    * idea: create a new collection mode

    / **
  * A: Case Demo
    * requirements: ArrayList deduplication value set strings (strings of the same content)
    * ideas: creating a new collection mode
    * /
      public static void main (String [] args) {
        the ArrayList List = the ArrayList new new ();
        List.add ( "A");
        List.add ( "A");
        List.add ( "B");
        List.add ( "B");
        List.add ( "B");
        List.add ( "C");
        List.add ( "C");
        List.add ( "C");
        List.add ( "C");

        System.out.println (List);
        the ArrayList newList = getSingle ( List);
        System.out.println (newList);
      }

    / *
      * Remove duplicates
      * 1, returns ArrayList
      * 2, the parameter list the ArrayList
      * /
    public static getSingle the ArrayList (the ArrayList List) {
      the ArrayList = new new newList the ArrayList (); // Create a new collection
      Iterator it = list.iterator (); // Get iterator
      while (it.hasNext ()) {// determines whether the old elements in the set
        String temp = (String) it.next ( ); // temporary recording element of each of live
        ! if (newList.contains (temp)) {// If a new collection does not contain the element
        newList.add (temp); // add the new elements to the collection
    }
}
        return newList; // return a new collection
}

Two, LinkedList unique features
    * A: LinkedList class overview
    * B: LinkedList class-specific features
      * public void addFirst (E e) and addLast (E E)
      * public E getFirst () and getLast ()
      * public E removeFirst () and E removeLast public ()
      * E public GET (int index);

Third, the queue data structure, and the stack
  * stack
    after an advanced *
  * queue
    * FIFO

Fourth, the set LinkedList analog stack data structure and test
  * A: Case Demo
    * requirements: Please set LinkedList analog stack data structure, and test
    * Create a class method of the package Linked the
    *
    public class Stack {
      Private LinkedList List = new LinkedList (); // Create Object LinkedList

      public void in (Object obj) {
      list.addLast (obj); // package addLast () method
    }

      public Object OUT () {
      return list.removeLast (); // package removeLast () method
  }

      public Boolean isEmpty () {
      return list.isEmpty (); // package isEmpty () method
    }
}

V. generic overview and basic use
  * A: Generics Overview
  * B: Generic benefits
    * improve safety (runtime error converting to compile)
    * eliminates the need for strong turn of trouble
    * C: generic basic use
    * <> must be put in the reference data types
  * D: Note the use of generics
    * generic must be the same before and after, or behind the generic can be omitted (new features diamond generics 1.7)

Six generic origin
  * A: Case presentation
    * generic origin: The Transformation of the introduction of Object
    * Early Object type can receive any type of object, but in actual use, there will be problems type conversion. This risk also exists, it provides a generic Java to solve this security problem.

Seven, and use of generic classes overview
  * A: Overview generic class <T>
    * defined in the generic class
  * B: Definition Format
    * public class name of the class <generic types. 1, ...>
    * C: Notes
    * generic type must be a reference type
  * D: case presentation
    * use a generic class

Eight, and an overview of the use of the generic method
  * A: generic method outlined
    * defined in the generic method
  * B: Definition Format
    * public <generic type> return type names (variable names generic type)
  * C: case presentations
    using generic methods *

Nine, and use generic interface overview
  * A: Overview Generic Interface
    * defined in the generic interface
  * B: Definition Format
    * public interface interface name <generic type>
  * C: Case Demo
    * using generic interface

Ten, the generic advanced wildcard
  * A: <?> Generic wildcard
    * any type, if not explicitly, then that Object as well as any of the Java class
  * B :? the extends E
    * limited downward, E and its subclasses
  * :? Super E C
    * defined upwardly, E and its parent


Eleven, for enhanced general description and the use of
  * A: Overview of Enhanced for
    * simplified array and a set of traversal Collection
  * B: Format:
  *
    for (data type variable element: Collection array or set) {
    use to variable, the variable is element
    }
  * C: case presentation
    * array, a collection of storage elements traversed by enhanced for
  * D: benefits
    * simplifies traversal


Twelve, ArrayList to store strings and custom objects and walk through enhanced for Version
  * A: Case presentation
    * ArrayList to store string and ergodic enhancements for Version
    *
      ArrayList <String> List = new new ArrayList <> ();
      list.add ( " A ");
      List.add (" B ");
      List.add (" C ");
      List.add (" D ");

      for (S String: List) {
        System.out.println (S);
      }
ten three three iterations can delete
  * ordinary for loop can be deleted, but the index should -
  * iterator can be deleted, but you must use the iterator's own remove method, otherwise there will be concurrent modification abnormal
  * enhanced for loop is not delete

Fourth, static import overview and use
  * A: Static Import Overview
  * B: Format:
    * Import static package name ... the name of the class method names;.
    * Can be imported directly into tier methods
    * C: Notes
    * method must be static, if there are still ways the same name, is easy to use do not know who?
    this time you want to use, you must prefix. Thus, little significance, it is generally not, but to be able to read.

Fifteen, Overview and using variable parameter
  * A: Overview of variable parameters
    * definition of the method when not know how many of the defined parameters
  * B: Format
    * Modifier return type method name (variable name data type ...)} {
  * C: Note:
    * variable here is actually an array
    * If there is a variable parameter method, and there are a number of parameters, then the variable parameters must be the last one

Guess you like

Origin www.cnblogs.com/zyyzy/p/12432457.html