If you are not worried about overflow or underflow, you can use Long::intValue , however, if you want to throw an exception, if that happens, you can do
Iterable<Integer> result = longList.stream() .map(Math::toIntExact)
If you prefer to โsaturateโ a value you can do
Iterable<Integer> result = longList.stream() .map(i -> (int) Math.min(Integer.MAX_VALUE, Math.max(Integer.MIN_VALUE, i))) .collect(Collectors.toList());
source share