Say I have a class like this:
public class EnglishWords {
private final String word1;
private final String word2;
private final String word3;
private final String word4;
public EnglishWords(String word1Arg, String word2Arg, String word3Arg, String word4Arg) {
this.word1 = word1Arg;
this.word2 = word2Arg;
this.word3 = word3Arg;
this.word4 = word4Arg;
}
public String getword1() {
return word1;
}
public String getword2() {
return word2;
}
public String getword3(){
return word3;
}
public String getword4(){
return word4;
}
}
I create an object like this:
EnglishWords englishWords = new EnglishWords(words.get(0),
words.get(1), words.get(2), wordPair.getEnglishWord());
Is there some kind of sort method I can add to the class that shuffles the members so they are ordered randomly?
Yes. You can hold them in a
Listand useCollections.shuffle()to shuffle the list.If you are eager to shuffle it by your own, or interested how it can be done – fisher-yates algorithm gives a uniformly distributed permutation of a given list.