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 4243506
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:35:13+00:00 2026-05-21T03:35:13+00:00

Which would be the best way to do it? Right now, I convert my

  • 0

Which would be the best way to do it? Right now, I convert my JSONArray to an ArrayList of a custom class, use Collections.shuffle() to perform the action, and convert back to JSONArray, which seems to be too much overhead.

The answer may be just to implement a
Fisher-Yates shuffle for it, but my guess is that this may be already done so I would like to avoid reinventing the wheel.
I looked at the standard JSON api and Google’s Gson but they don’t seem to have any implementation.

There are also simple options for a standard array in this question that could be easily ported to java, but I would gladly hear your input. I am amazed that the query http://www.google.com/search?q=java+shuffle+jsonarray did not flood me with methods.

  • 1 1 Answer
  • 0 Views
  • 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-21T03:35:14+00:00Added an answer on May 21, 2026 at 3:35 am

    Sorry for posting an answer to my own question, but right now, since there was no out-of-the-box quick solution, I’m implementing my own static shuffle function based on the code from this post: Random shuffling of an array . Still looking forward to hear about the best implementation. This is what I did:

    public static JSONArray shuffleJsonArray (JSONArray array) throws JSONException {
        // Implementing Fisher–Yates shuffle
            Random rnd = new Random();
            for (int i = array.length() - 1; i >= 0; i--)
            {
              int j = rnd.nextInt(i + 1);
              // Simple swap
              Object object = array.get(j);
              array.put(j, array.get(i));
              array.put(i, object);
            }
        return array;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What would be the best way to compare two date in java? Right now
I'm taking a C# class right now and I'm trying to find out the
I'm running into API Limit Requests which end up blowing my site up. Right
I have a weird background I am trying to figure out the best way
hey guys, i know it's not the best way of doing this but the
I am developing an app that lets the user record videos and photos. Now
I have tried my best to answer this question myself through research but I
I'm writing a Junit test in which the expected result is a XML string.
I'm adding a new feature to my user module for my CMS and I've
Essentially, I currently have an iPhone app that can query and parse an XML

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.