Sort Sort
BinarySearch Find
Fill Change all of the list
ReplaceAll covers all the same
Reverse Invert the contents of a collection
Swap swap Operations
Shuffle random allocation, is the order of disruption
Comparator use of external comparators
Import java.util.*;p ublic class anli{public static void Main (string[] args) {//binarysearchdemo ();//reverseorderdemo () ; Randomdemo ();} public static void Randomdemo () {Random rd = new random ();//random integer, Random is non-generic, without parameter sop (Rd.nextint (10));//Specified range}public static void Binarysearchdemo () {list<string> List = new arraylist<string> () List.add ("ADF"); List.add (" Adgaf "), List.add (" ADFRWREWRDF "), List.add (" ADSFASFF "), List.add (" AF "), List.add (" ARWDFC "), SOP (list); Collections.sort (list,new com ()),//collections.sort (list), SOP (list), int index = Collections.binarysearch (list, "AF" , new COM ());//To pass the comparator over to SOP (index);//collections.fill (list, "AV"); Change the list of all//sop (lists),//collections.replaceall (list, "av", "va");//cover all the same//sop (list); Collections.reverse (list); SOP (list); Collections.swap (list,0,1);//exchange operation, must be in the list collection. SOP (list); Collections.shuffle (list);//Randomly assigned SOP (list);} public static void Sop (Object obj) {System.out.println (obj);} public static void Reverseorderdemo () {//treeset<string> ts = new treeset<String> (Collections.reverseorder ());//Because it is a return comparator, it needs to be set or map structure//treeset<string> ts = new treeset< String> (Collections.reverseorder (New COM ()));//The order in which the comparator of the strong turn changes. treeset<string> ts = new treeset<string> (new COM ()), Ts.add ("ADF"), Ts.add ("ASFADF"), Ts.add ("Agsfaddf"); Ts.add ("ADSDDSF"); Ts.add ("asdf"); Ts.add ("AF");iterator<string> it = Ts.iterator (); while (It.hasnext ()) { String str = it.next (); SOP (str);}}} Class COM implements comparator<string>{public int compare (String one,string) {int value = One.length ()- Two.length (); if (One.length () ==two.length ()) {return One.compareto (both);} return value;}}
Collections classes that specialize in manipulating collections