-3

I have an empty list of integers:

final List<Integer> reservedMarkers = new ArrayList<>();

and I will fill this list with the marker property of a list of objects, such like this:

scheduleIntervalContainers.stream().forEach(s -> s.getMarker(), reservedMarkers.add(s));

My final target would be to get the highest marker number but actually I dont know a better way as getting all marker numbers, than sort it and than get the highest one.

this does not work for sure, is there a possibility to do this in this way?

1
  • 2
    There are other methods than forEach. And there is a documented API. Look there first. Commented Jul 4, 2016 at 11:19

1 Answer 1

1

Use IntStream to find max value:

OptionalInt max = scheduleIntervalContainers.stream()
    .mapToInt(s -> s.getMarker())
    .max();
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.