Count repeated elements in an array in java