+ 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?
3 Answers
+ 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/
+ 2
Gino ^^ We always have Arrays.asList() if String arrays fail. :>
+ 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