+ 1

Shuffle Method for String Array?

Hey! I know that there is a method for arrays sort() that sorts an array. But is there also something like shuffle()? Say I have this code: String st = "a b c"; String[] ar = st.split(" "); Now what if I want to print each letter only one randomly?

11th Feb 2019, 1:10 PM
Gino ^^
Gino ^^ - avatar
3 Respostas
+ 2
You can look at the .shuffle method of Collections. It could be just what you need. https://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#shuffle(java.util.List) G4G: https://www.geeksforgeeks.org/collections-shuffle-java-examples/
11th Feb 2019, 1:34 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
Gino ^^ We always have Arrays.asList() if String arrays fail. :>
11th Feb 2019, 1:43 PM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Hatsy Rei Cool thank you! But do I have to convert it into a list or can I also do it with a String Array
11th Feb 2019, 1:42 PM
Gino ^^
Gino ^^ - avatar