Some common methods of Java collection Operation class collections

Source: Internet
Author: User

 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

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.