ควิซ Java: Comparable & Comparator

This Java quiz covers sorting objects. You will read compareTo() results, build comparators with Comparator.comparing(), reversed() and thenComparing(), and find out what happens when a class has no natural order or a TreeSet thinks two values are equal.

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

เลือกโหมด

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

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

ข้อ 1 จาก 10

a.compareTo(b) returns a negative number. What does that mean?

ดูเฉลย

D. a comes before b compareTo() returns a negative number if a sorts before b, zero if they are equal and a positive number if a sorts after. Only the sign matters, not the exact value.

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

  • What compareTo() returns and what it means
  • Implementing Comparable for natural order
  • Comparator.comparing(), reversed(), thenComparing()
  • Sorting objects that are not Comparable
  • The a - b comparator bug and TreeSet duplicates

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

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

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

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

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