Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,971 questions

51,913 answers

573 users

How to shuffle a string in Java

1 Answer

0 votes
import java.util.List;
import java.util.Arrays;
import java.util.Collections;

public class MyClass {
    public static String shuffleString(String s) {
      List<String> chars = Arrays.asList(s.split(""));
      Collections.shuffle(chars);
      
      String shuffled = "";
      for (String ch : chars) {
        shuffled += ch;
      }
      
      return shuffled;
    }
    public static void main(String args[]) {
        String s = "java c++ php python";
        
        s = shuffleString(s);
        
        System.out.println(s);
    }
}




/*
run:

cjhnpyta+ov p pah+

*/

 



answered Mar 28, 2021 by avibootz

Related questions

2 answers 143 views
143 views asked Nov 8, 2023 by avibootz
2 answers 109 views
109 views asked Mar 25, 2023 by avibootz
2 answers 140 views
140 views asked Oct 30, 2021 by avibootz
1 answer 146 views
146 views asked Mar 29, 2021 by avibootz
1 answer 255 views
255 views asked Mar 15, 2021 by avibootz
1 answer 164 views
1 answer 72 views
72 views asked Nov 5, 2024 by avibootz
...