I'm making a yahtzee game in java, and I have a variable called frequencyCount which is an array keeping track of how many die there is of each one. I reset this array after each roll with a for loop setting each index to 0.
for(int i = 0; i < frequencyCount.length; i++) {
frequencyCount[i] = 0;
}
But is there any problem with just creating a new array each time like this:
frequencyCount = new int[6];
The reset method will be called 45 times per player per game.
Which way is best? Is it a problem to keep creating new arrays, or doesn't it matter since this is a small game?
Arrays.fill(frequencyCount, 0);(which just saves you from writing the loop yourself).ArrayListimplementation of theListinterface - it has a very convenientclear()method.