Introduction to List learning of Java Collection

  • 2020-04-01 01:44:50
  • OfStack

The List An ordered set that allows the repetition of elements; The implementation is not synchronous, and if multiple threads access a List instance, and at least one of them structurally modifies the table (adding or removing elements), it needs to be kept externally synchronized. Generally based on the natural encapsulation synchronous operation to complete the list of objects, such as: Collections. SynchronizedList () to the packing list;

 

ArrayList An implementation of a variable-size array of the List interface that implements all optional List operations and allows all elements, including null,

 

LinkedList The linked List implementation of the List interface, allows elements to be null, implements all optional List operations, and provides implementations for get, remove, and insert at the beginning and end of lists.

ArrayList al = new ArrayList();  

The Iterator it = al. ListIterator (); // can operate on the iterated object;
    While (it. HasNext ())
    {
      String STR = (String) it. Next ();
      If (STR = = "abcd")
        It. The remove ();
      System. The out. Println (STR);
    }

Al:
    [ABC, the abcd, abcde] - > [ABC, abcde]


Related articles: