Java Collection Framework-tool class collections

Source: Internet
Author: User

1.Collections Overview

is a tool class for collection operations.


What is the difference between 2.Collection and collections?

Collection: Is the top-level interface for a single-column collection, and collections is a tool class for collection operations.

Collection has sub-interfaces list and set, and collections has a method for sorting and binary lookups of the collection.


Features of the 3.Collections tool class

public static <T> void sort (list<t> List): The natural sort of collection is by default.

public static <T> int BinarySearch (list<?> list,t key): Two-point lookup

public static <T> T Max (collection<?> coll): Maximum value

public static void reverse (list<?> List): Invert

public static void Shuffle (list<?> List) random substitution

Package Com;import Java.util.arraylist;import Java.util.collections;import Java.util.list;public class Collectionsdemo {public static void main (string[] args) {list<integer> List = new arraylist<integer> (); List.add (List.add), List.add ( -50); List.add (+); List.add (40); System.out.println ("list:" +list); Collections.sort (list); System.out.println ("list:" +list); System.out.println (Collections.max (list)); Collections.reverse (list); System.out.println ("list:" +list); Collections.shuffle (list); System.out.println ("list:" +list);}}

LIST:[20,-50, 100, 50, 40]

LIST:[-50, 20, 40, 50, 100]

100

LIST:[100, 50, 40, 20,-50]

LIST:[100, 20,-50, 40, 50]






This article is from the "11831428" blog, please be sure to keep this source http://11841428.blog.51cto.com/11831428/1864533

Java Collection Framework-tool class collections

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.