I have an array, size can be up to 10000. It holds only 1/2/3/4. I need to find how many 1s, 2s, 3s and 4s are there in the array. What's the fastest way of doing it? My language of use is Java. My piece of code-
for(int i=0; i<myArray.length;i++){
int element = myArray[i];
if(element == 1){
onesCount++;
}
else if(element == 2){
twosCount++;
}
else if(element == 3){
threesCount++;
}
else
foursCount++;
}
I hope there's a good solution.