ควิซ Java: Lambdas & Streams

This Java quiz tests lambdas and the Stream API that came with Java 8. You will predict what pipelines print, see why streams are lazy and single-use, and match lambdas to functional interfaces.

ปานกลาง 10 ข้อ ~6 นาที ผ่านที่ 80% Java 17

เลือกโหมด

กำลังเล่นแบบผู้เยี่ยมชม: เข้าสู่ระบบเพื่อเก็บ XP และ streak

ตัวอย่างคำถาม

ข้อ 1 จาก 10

What does this print?

import java.util.List;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        List<Integer> nums = List.of(1, 2, 3, 4, 5, 6);
        List<Integer> result = nums.stream()
            .filter(n -> n % 2 == 0)
            .map(n -> n * n)
            .collect(Collectors.toList());
        System.out.println(result);
    }
}
ดูเฉลย

A. [4, 16, 36] filter keeps the even numbers 2, 4 and 6, then map squares each of them. The original list is not changed; collect builds a new one.

ควิซนี้มีเนื้อหาอะไรบ้าง

  • filter, map, reduce and collect
  • Lazy evaluation and the order in which elements flow
  • Streams can be used only once
  • Effectively final variables in lambdas
  • Collectors.joining, groupingBy, Optional and functional interfaces

คำถามที่พบบ่อย

ต้องมีบัญชีไหม?

ไม่ต้อง ใครก็เล่นได้ เข้าสู่ระบบเพื่อเก็บ XP, streak, เหรียญตรา และประวัติ

ทำซ้ำได้ไหม?

ได้ ระบบเก็บคะแนนที่ดีที่สุดไว้ และสลับคำถามกับตัวเลือกใหม่ทุกครั้ง