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