Seems like there is no such thing in the standard library.
But it is very easy to do yourself! You just create an array with the size of 4. Then add values to it. Once it has 3 values and you're trying to add a 4th one, add it as fourth and sort your list. Now any time you add another value simply overwrite the 4th one and sort again.
Here is a very short example script that should give you the idea:
import java.util.Arrays;
public class TempTest {
static int[] topThree = new int[4];
static public void addValue(int newVal) {
if (newVal > topThree[0]) {
topThree[0] = newVal;
Arrays.sort(topThree);
}
}
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
int newInt = (int) (Math.random() * 30);
System.out.println("Adding " + newInt);
addValue(newInt);
System.out.println(Arrays.toString(topThree));
}
}
}
Results in this output:
Adding 23
[0, 0, 0, 23]
Adding 16
[0, 0, 16, 23]
Adding 2
[0, 2, 16, 23]
Adding 8
[2, 8, 16, 23]
Adding 28
[8, 16, 23, 28]
Adding 12
[12, 16, 23, 28]
Adding 0
[12, 16, 23, 28]
Adding 29
[16, 23, 28, 29]
Adding 6
[16, 23, 28, 29]
Adding 5
[16, 23, 28, 29]