Package java.util

Examples of java.util.OptionalInt


    s4.addExamResult(new ExamResult("Chemistry", 65));
    s4.addExamResult(new ExamResult("Maths", 82));
    students.add(s4);

    //@formatter:off
    OptionalInt optionalInt = students.stream()
      .filter(s -> s.getGraduationDate().getYear() == 2014)
      .flatMap(s -> s.getExamResults().stream())
      .filter(er -> "Maths".equals(er.getExam()))
      .mapToInt(er -> er.getScore()) // Use specialised version of map function to get an IntStream
      .max(); // IntStream.max() is a short-cut for Stream.reduce(Integer::max)
    //@formatter:on   

    assertThat(optionalInt.isPresent(), is(true));
    assertThat(optionalInt.getAsInt(), is(76));
  }
View Full Code Here

TOP

Related Classes of java.util.OptionalInt

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.