ควิซ Java: HashSet

This Java quiz covers HashSet and its relatives LinkedHashSet and TreeSet. You will predict what add() returns, how sets treat your own classes and records, how set operations work and why changing an element inside a set breaks it.

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

เลือกโหมด

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

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

ข้อ 1 จาก 10

What does this print?

import java.util.HashSet;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Set<String> s = new HashSet<>();
        System.out.println(s.add("a") + " " + s.add("a") + " " + s.size());
    }
}
ดูเฉลย

B. true false 1 add() returns true only when the element was not already in the set. The second a is a duplicate, so it returns false and the size stays 1.

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

  • add() returns false for duplicates
  • How equals() and hashCode() define duplicates
  • Records as set elements
  • retainAll() and other set operations
  • HashSet vs LinkedHashSet vs TreeSet

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

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

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

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

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