Collection class and Common API

Source: Internet
Author: User
Tags shuffle

Collection class and Common API

The collection-class Set tool class defines several algorithms for class sets and mappings that are defined as static methods to view the API documentation;

A) public static void sort (list<t> liet)

b) public static int BinarySearch (list<t> list,t key)

c) public static void reverse (list<?> List)

d) public static void Shuffle (List<?> List)

e) public static void swap (list<?> list,int i,int J)

f) public static <T> void Fill (list<? super t> List,t obj)

1List<string> nlist=NewArraylist<string>();2Nlist.add ("Zhangsan");3Nlist.add ("Lisi");4Nlist.add ("Wangwu");5Nlist.add ("Zhaoliu");6Nlist.add ("Tianqi");7System.out.println ("Before Operation");8          for(String s:nlist) {9System.out.print (s+ "");Ten         } One          A System.out.println (); -SYSTEM.OUT.PRINTLN ("After Exchange order"); -Collections.swap (nlist,1,2); the          for(String s:nlist) { -System.out.print (s+ ""); -         } -          + System.out.println (); -System.out.println ("After natural sorting"); + Collections.sort (nList); A          for(String s:nlist) { atSystem.out.print (s+ ""); -         } -          - System.out.println (); -SYSTEM.OUT.PRINTLN ("Binary search")); -System.out.println (Collections.binarysearch (nList, "Zhaoliu")); in          -SYSTEM.OUT.PRINTLN ("Scramble Order")); to collections.shuffle (nList); +          for(String s:nlist) { -System.out.print (s+ ""); the         } *          $ System.out.println ();Panax NotoginsengSystem.out.println ("Fill"); -Collections.fill (NList, "Jay"); the          for(String s:nlist) { +System.out.print (s+ ""); A}

Output Result:

Before operation

Zhangsan Lisi Wangwu Zhaoliu Tianqi

After Exchange order

Zhangsan Wangwu Lisi Zhaoliu Tianqi

After natural sorting

Lisi Tianqi Wangwu Zhangsan Zhaoliu

Binary Method Search

4

Scramble Order

Zhaoliu Tianqi Wangwu Zhangsan Lisi

Fill

Jay Jay Jay Jay

Collection class and Common API

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.