0
int [] numList = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int rangeLowerBound = 2
int rangeUpperbound = 8

Is there some sort of standard way to grab a group of numbers from the array that fall within the range, then put those numbers into a new Array?

1 Answers1

1

Assuming this range is inclusive,

int[] inRange = Arrays.stream(numList).filter(x -> x >= rangeLowerBound && x <= rangeUpperbound).toArray();
// inRange = [2, 3, 4, 5, 6, 7, 8]
JamieT
  • 1,177
  • 1
  • 9
  • 19