I have an Integer array and I want to randomly take an element from those who are not null. I have tried this but after the else, I cannot use return because the method is int. But I don't know what to write after else in order to return at the beginning and take a new random element.
public int getRandomPosition(){
Random x = new Random();
int b = x.nextInt(2*number0fCardPairs);
if (myArray[b] != null){
return b;
}
else{
return;
}
}