Question 21

Given the code fragment:
List<String> str = Arrays.asList ("my", "pen", "is", "your', "pen"); Predicate<String> test = s -> {
int i = 0;
boolean result = s.contains ("pen");
System.out.print(i++) + ":");
return result;
};
str.stream()
.filter(test)
.findFirst()
.ifPresent(System.out ::print);
What is the result?
  • Question 22

    Given:
    class Student {
    String course, name, city;
    public Student (String name, String course, String city) {
    this.course = course; this.name = name; this.city = city;
    }
    public String toString() {
    return course + ":" + name + ":" + city;
    }
    public String getCourse() {return course;}
    public String getName() {return name;}
    public String getCity() {return city;}
    and the code fragment:
    List<Student> stds = Arrays.asList(
    new Student ("Jessy", "Java ME", "Chicago"),
    new Student ("Helen", "Java EE", "Houston"),
    new Student ("Mark", "Java ME", "Chicago"));
    stds.stream()
    .collect(Collectors.groupingBy(Student::getCourse))
    .forEach(src, res) -> System.out.println(scr));
    What is the result?
  • Question 23

    Which statement is true about java.time.Duration?
  • Question 24

    Given the code fragment:
    List<String> codes = Arrays.asList ("DOC", "MPEG", "JPEG");
    codes.forEach (c -> System.out.print(c + " "));
    String fmt = codes.stream()
    .filter (s-> s.contains ("PEG"))
    .reduce((s, t) -> s + t).get();
    System.out.println("\n" + fmt);
    What is the result?
  • Question 25

    Given:

    and the code fragment:

    What is the result?