Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3982602
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:32:50+00:00 2026-05-20T05:32:50+00:00

suppose I have arraylist of integers…is there a way that I can generate a

  • 0

suppose I have arraylist of integers…is there a way that I can generate a random permutation/arrangement of the elements in the arraylist

so if the list is {1,2,3,4,5,6}

calling some method randomPermute() would change it to something random like

{1,3,2,6,5,4}

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:32:51+00:00Added an answer on May 20, 2026 at 5:32 am

    Collections.shuffle() does the job:

    public static void shuffle(List<?> list) –
    Randomly permutes the specified list using a default source of randomness. All permutations occur with approximately equal likelihood.
    http://download.oracle.com/javase/6/docs/api/java/util/Collections.html#shuffle(java.util.List)

    For example

        ArrayList<Integer>anArrayList = new ArrayList<Integer>();
        anArrayList.add(1);
        anArrayList.add(2);
        anArrayList.add(3);
        anArrayList.add(4);
        anArrayList.add(5);
        System.out.println(anArrayList);
        Collections.shuffle(anArrayList);
        System.out.println(anArrayList);
    

    Sample Output

    [1, 2, 3, 4, 5]
    [3, 5, 1, 2, 4]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose i have a List<Integer> l = new ArrayList<Integer>(); and would like to have
I have object arraylist,I have to apply search operation on name basis.suppose there are
How can I remove specific object from ArrayList? Suppose I have a class as
I have to find a best way to find out that elements which is
In Java, suppose I have a method that takes in two lists of integers,
First array list:- ArrayList<Object> list1; Second array list:- ArrayList<Object> list2; Suppose I have filled
Suppose I have an ArrayList<Fruit> I would like to get all elements from this
I have an ArrayList suppose list , and it has 8 items A-H and
Suppose I have a large list of words. For an example: >>> with open('/usr/share/dict/words')
Suppose I have a pure virtual method in the base interface that returns to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.