You could just eliminate the values above 90% or 95%. Technicaly you calculate the p = 0.9 (or 0.95) percentile of the array distribution.
Just sort the array ascending:
int[] data;
Arrays.sort(data); // or use ArrayList<Integer> which has Collections.sort(dataArrayList),
Then calculate position of percentile p:
float p = data.length * p; // e.g p = 0.9 for 90% percentile.
// cut of fractional part.
int posInt = (int) p;
// this is the threshold value
int threshold = data[posInt]
Now filter array by keeping all value < or <= threshold. This keeps the 90% of smallest values.
int i = 0;
while (i < data.length && data[i] <= threshold) {
// output data[i];
}
For mathematically "perfect" results you could search for "calculate percentile of discrete array / values).
As i remeber there are two valid algorithms, describeing whether one has to round down or round up the posInt
. I my example above I just truncated.