Java Quiz: 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, badge और हिस्ट्री सेव रखने के लिए साइन इन करें।

क्या मैं इसे दोबारा दे सकता हूं?

हां। आपका बेस्ट स्कोर सेव रहता है, और हर बार सवाल और जवाब शफ़ल होते हैं।