Public Static voidMain (string[] args) {List<Integer> list =NewArraylist<integer>(); List.add (34); List.add (55); List.add (56); List.add (89); List.add (12); List.add (23); List.add (126); SYSTEM.OUT.PRINTLN (list); //to sort a collectionCollections.sort (list); SYSTEM.OUT.PRINTLN (list); //to randomly sort a collectioncollections.shuffle (list); SYSTEM.OUT.PRINTLN (list); //Gets the collection maximum, minimum value intMax =Collections.max (list); intMin =collections.min (list); System.out.println ("Max:" + Max + "Min:" +min); List<String> List2 = arrays.aslist ("Monday,tuesday,wednesday,thursday,friday,saturday,sunday". Split (",")); System.out.println (LIST2); //finds the specified element of the collection, returns the index of the element//if the element does not exist, n indicates the location index where the element is most likely to exist intIndex1 = Collections.binarysearch (List2, "Thursday"); intIndex2 = Collections.binarysearch (List2, "TTTTTT"); System.out.println (INDEX1); intn =-index2-1; //find where a substring first appears in the collectionlist<string> sublist = arrays.aslist ("Friday,saturday". Split (",")); intIndex3 =collections.indexofsublist (List2, sublist); System.out.println (INDEX3); intINDEX4 =collections.lastindexofsublist (List2, sublist); System.out.println (INDEX4); //replaces the specified element in the collection, or returns False if the element exists that returns true BooleanFlag = Collections.replaceall (List2, "Sunday", "TTTTTT"); SYSTEM.OUT.PRINTLN (flag); System.out.println (LIST2); //reverses the order of elements in the collectionCollections.reverse (LIST2); System.out.println (LIST2); //swap the position of the specified element in the collectionCollections.swap (List2, 0, 3); System.out.println (LIST2); //replaces all elements in the collection with ObjectCollections.fill (List2, "replace"); System.out.println (LIST2); //generates a collection of specified size and contentlist<string> list4 = collections.ncopies (5, "haha"); System.out.println (LIST4); }
Some common methods of Java collection Operation class collections