The use of shuffle in JAVA's collections class __java

Source: Internet
Author: User
Tags shuffle

is to randomly disrupt the original order, and shuffle the same. Such as:

Shuffletest.java import java.util.*; public class Shuffletest {public static void main (string[] args) {list<integer> List = new Arraylist<integer> ;(); for (int i = 0; i < i++) List.add (new Integer (i)); System.out.println ("Before Upset:"); SYSTEM.OUT.PRINTLN (list); for (int i = 0; i < 5; i++) {System.out.println ("the first" + i + "The second Upset:"); Collections.shuffle (list); SYSTEM.OUT.PRINTLN (list); } } }

Output results:

Before the disruption:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
No. 0 Time Upset:
[6, 3, 2, 0, 8, 1, 7, 5, 4, 9]
1th Time Upset:
[6, 2, 3, 0, 8, 5, 7, 4, 9, 1]
2nd time Upset:
[1, 7, 9, 4, 6, 0, 2, 5, 3, 8]
3rd time Upset:
[0, 4, 2, 8, 9, 1, 3, 7, 5, 6]
4th Time Upset:
[8, 1, 3, 0, 7, 9, 4, 2, 5, 6]

Excerpt from: http://topic.csdn.net/u/20080308/17/642f73e3-ff7b-4144-a52b-190a72be1e49.html

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.