Example:
wordsUsed[0][0] = "Word 1";
wordsUsed[0][1] = "0";
wordsUsed[1][0] = "Word 2";
wordsUsed[1][1] = "0";
String wordsCopy[][] = new String[2][2]
What I want is that wordsCopy[][] contains "Word 1" 2 times and "Word 2" also 2 times. what I don't want is random amount of times of "Word 1" and random amount of times "Word 2"
wordsUsed[x][0]
^is a string with a word in it // x meaning 'any value'
wordsUsed[x][1]
^is standard "0"
wordsCopy[][]
^is a new array that will store 2 of each string in kleurGebruikt[x][0]
Basicly what I'm trying to accomplish is that the same string from [x][0] is never stored more than 2 times in the new array
What I got so far is that it will check the counter and if it is 0 it will copy the string over and then change the 0 to 1. if it gets the same string later it will see that it is already used once and copy it once more. Now my problem is that when it is copied twice, I'm unsure of how to make it skip this string and try a different one. Any help is appreciated
public void randomWords() {
Random r = new Random();
int rndm = 0;
for(int i=0; i<4; i++){
for(int j=0; j<5; j++){
rndm = r.nextInt(wordsUsed.length);
if (wordsUsed[rndm][1].equals("0")){
wordsCopy[i][j] = wordsUsed[rndm][0];
wordsUsed[rndm][1] = "1";
}
else if (wordsUsed[rndm][1].equals("1")){
wordsCopy[i][j] = wordsUsed[rndm][0];
wordsUsed[rndm][1] = "2";
}
else if (wordsUsed[rndm][1].equals("2")){
// at this point I need to go back to the start of the current
// if loop and make it so that a new random string is searched for
// without leaving a null element in the array.
}
}
Btw I'm sorry if the title isn't really good. I wasn't really sure how to explain myself in just a few words
Thanks
equalsto compare strings. Other than that, please explain what you want with an example.kleurGebruiktin a list and then duplicate it as many times in your second 2D array.