I have seen you can do this using ArrayLists
, but is it possible to do this using a normal object array?
deleting an object from an array [java]
At the start of each the player is given 3 random dice from a cup.
The cup has 13 dice in total.
When the player is given the 3 dice from the cup the cup should have only 10 dice in left. I was trying to set the value to null
but this still counts as a index in the array so the length does not change.
// Removing the 3 dice which were picked form the cup of the current player, the diceToTakeOut is a String array with a length of 3 the newTurnCup is a Object array with a length of 13
public static Dice [] cup(String [] diceTotakeOut, Dice [] newTurnCup){
for (int i = 0; i < diceTotakeOut.length; i++) {
if (diceTotakeOut.length > 0) {
if (diceTotakeOut[i] == newTurnCup[i].getName()) {
newTurnCup[i] = null;
}
}
}
return newTurnCup;
}
I have tried a few different ways which I could think of:
newTurnCup[i] = null;
newTurnCup[i] = newTurnCup[i - 1];
The result would be after each turn the array holding the dice would have 3 index less.