Java basic learning notes 7 (1) -- Collection interface & Collections Collection tool class

Source: Internet
Author: User

* ** The container API Collection interface defines how to access a single object. Its Sub-interfaces define the storage methods and forms respectively. 1. List: the stored data is ordered and can be repeated. 2. set: the stored data is not ordered and cannot be duplicated. the Map interface defines A method used to store "key-value pairs". *** Collection a collection represents A group of objects, known as its elements. some collections allow duplicate elements and others do not. some are ordered and others unordered. when a container Class Object calls methods such as remove and contains, it needs to compare whether the objects are equal. This involves the equals and hashcode methods of the objects. For classes defined by yourself, you need to override the equals and hashcode methods. NOTE: If equals is true, the value of hashCode should be equal. HashCode can be used to find the address where data is stored in the memory. The hashCode method is more suitable than the equals method block. hashCode is suitable for indexing. * ** Common methods of tool classes in Collections set 1. void sort (List) Sorts the specified list into ascending order, according to the natural ordering of its elements. sort the elements in the List (faster sort List) 2. void shuffle (List) Randomly permutes the specified list using a default source of randomness to Randomly arrange objects in the List container. void reverse (List) www.2cto.com Reverses the order of the elements in the specified list to flip the elements in the specified List. 4. void fill (Li St, Object) Replaces all of the elements of the specified list with the specified element. replace all elements in the specified list with the specified element. 5. void copy (List dest, List src) Copies all of the elements from one list into another. copy all elements from one List to another. Copy the contents of the Src List container to the dest List container 6.int binarySearch (List list, Object obj) Searches the specified list for the specified object using the binary search algorithm. returns a list by using the binary method to obtain the specified object. Find the specified Element in the specified list

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.