热门面试题与答案和在线测试
面向面试准备、在线测试、教程与实战练习的学习平台

通过聚焦学习路径、模拟测试和面试实战内容持续提升技能。

WithoutBook 将分主题面试题、在线练习测试、教程和对比指南整合到一个响应式学习空间中。

面试准备

Java 8 面试题与答案

Test your skills through the online practice test: Java 8 Quiz Online Practice Test

相关差异对比

Java 7 vs Java 8Java 8 vs Java 9

问题 16. Given a list of employees, sort all the employee on the basis of age by using java 8 APIs only.

You can simply use sort method of list to sort the list of employees.
List<Employee> employeeList = createEmployeeList();
        employeeList.sort((e1,e2)->e1.getAge()-e2.getAge());
        employeeList.forEach(System.out::println);

这有帮助吗? 添加评论 查看评论
 

问题 17. Given the list of employees, find the employee with name 'John' using Java 8 API.

Check the following code:
List<Employee> employeeList = createEmployeeList();
        Optional<Employee> e1 = employeeList.stream()
                  .filter(e->e.getName().equalsIgnoreCase("Mary")).findAny();
        if(e1.isPresent())
            System.out.println(e1.get());

这有帮助吗? 添加评论 查看评论
 

问题 18. Given a list of employee, find maximum age of employee using Java 8 API.

Check the following code:
List<Employee> employeeList = createEmployeeList();
        OptionalInt max = employeeList.stream().
                          mapToInt(Employee::getAge).max();
        if(max.isPresent())
            System.out.println("Maximum age of Employee: "+max.getAsInt());

这有帮助吗? 添加评论 查看评论
 

问题 19. Difference between Intermediate and terminal operations in Stream.

Java 8 Stream supports both intermediate and terminal operation.
  • Intermediate operations are lazy in nature and do not get executed immediately. Terminal operations are not lazy, they are executed as soon as encountered.
  • Intermediate operation is memorized and is called when terminal operation is called.
  • All Intermediate operations return stream as it just transforms stream into another and terminal operation don't.

这有帮助吗? 添加评论 查看评论
 

问题 20. Provide some examples of Intermediate operations.

Example of Intermediate operations are:
  • filter(Predicate)
  • map(Function)
  • flatmap(Function)
  • sorted(Comparator)
  • distinct()
  • limit(long n)
  • skip(long n)

这有帮助吗? 添加评论 查看评论
 

用户评价最有帮助的内容:

版权所有 © 2026,WithoutBook。