Java basic learning notes 7 (2) -- List & amp; Set

Source: Internet
Author: User

* ** List interface An ordered collection (also known as a sequence ). unlike sets, lists typically allow duplicate elements. the List interface is a Collection sub-interface. The elements in the container class that implements the List interface are ordered and can be repeated. Each element in the List container corresponds to an integer sequence number, which records its position in the container. You can obtain the elements in the container according to the sequence number. ArrayList -- List objects List implemented by arrays at the underlying layer -- List objects List implemented by linked lists at the underlying layer. Common Methods: 1. object get (int index) Returns the element at the specified position in this list. returns the element 2 at the specified position in this list. object set (int index, Object element) Replaces the element at the specified position in this list with the specified element Replaces the element at the specified position in the list with the specified element. 3. void add (E e) Appends the specified element to the end of this list to append the specified element to the end of this list. 4. void add (int index, E element) Inserts the specified element at the specified position in this list Insert the specified element into the specified position in this list. object remove (int index); Removes the element at the specified position in this list. removes an element from the specified position in the list. 6. int indexOf (Object o) Returns the index of the first occurrence of the specified element in this list, if-1 7.int lastIndexOf (Object o) Returns the index of the last occurrence of the specified element in this list is not returned. returns the location index of the last occurrence of the specified object in the list. * ** Set interface A collection that contains no duplicate elements. A collection that does not contain duplicate elements. More formally, set does not contain elements e1 and e2 that meet e1.equals (e2), and can contain at most one null element. The main implementation class HashSet can be used to filter data. For the Set method, refer to the API *** to compare the selected data structure-Read efficiency and change efficiency-Array-fast reading and slow modification (when the program reads a lot) Linked-slow reading, fast modification (many changes to the program) Hash-between the two

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.