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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:14:04+00:00 2026-05-16T00:14:04+00:00

How do I shuffle the characters in a string (e.g. hello could be ehlol

  • 0

How do I shuffle the characters in a string (e.g. hello could be ehlol or lleoh or …). I don’t want to use the Collections.shuffle(...) method, is there anything simpler?

  • 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-16T00:14:05+00:00Added an answer on May 16, 2026 at 12:14 am

    I dont know anything simpler. But you can use the Math.rand() functionality to generate a random number within the range of the character’s length without replace and that would give you a shuffled output

    public class Shuffle {
        public static void main(String[] args) {
            Shuffle s = new Shuffle();
            s.shuffle("hello");
    
        }
        public void shuffle(String input){
            List<Character> characters = new ArrayList<Character>();
            for(char c:input.toCharArray()){
                characters.add(c);
            }
            StringBuilder output = new StringBuilder(input.length());
            while(characters.size()!=0){
                int randPicker = (int)(Math.random()*characters.size());
                output.append(characters.remove(randPicker));
            }
            System.out.println(output.toString());
        }
    }
    /*
    Sample outputs
    hlleo
    llheo
    leohl
    lleho
    */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a simple shuffle function for Scala lists? If not, whats the simplest
Is there a way to trigger a shuffle in windows wallpaper slideshow? Preferably something
i want after i shuffle a list of images to get all the alt=
I want to know how to shuffle the images.If i drag an image into
I want to shuffle an array in java but not to change the original
I want to shuffle an array of elements in JavaScript like these: [0, 3,
There is a line in Rails Tutorial: ('a'..'z').to_a.shuffle[0..7].join that can generate zwnrfxte , but
I understand how str_shuffle() or shuffle works but I don't know it in this
I want to shuffle the lines of a text file randomly and create a
I want to show the shuffle word inside the Textfield. so far this is

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.