private static final Random random = new Random();
public static Integer[] generateRandomIntArray(int size) {
return IntStream.range(0, size).map(i -> random.nextInt(size)).boxed()
.toArray(Integer[]::new);
}
Reverse an array:
IntStream.range(0, randomNumbers.length / 2)
.forEach(i -> swap(randomNumbers, i, randomNumbers.length - i - 1));
Do bubble sort:
IntStream.range(0, items.length)
.forEach(i -> IntStream.range(i + 1, items.length)
.filter(j -> items[i]> items[j])
.forEach(j -> swap(items, i, j)));