«
Prev
»
Next
OOPS Concepts and its implementation in Java (19)
Inheritance (29)
Java Identifiers (4)
JDK, JRE, JVM, JIT (69)
Object, Class and Package (44)
Variable (9)
Instance Variables (Non Static Variables) (3)
Local Variables (6)
Class Variables (Static Variables) (13)
Package (10)
Operators (9)
Modifiers (29)
Methods (39)
Data types (10)
Access Modifiers (5)
Control Statements (14)
Constructor (38)
Interface (46)
Abstract Class (19)
Enum (20)
Arrays (20)
Strings (32)
Using String (29)
Exception (55)
Collections (56)
List and its implementations (22)
Set and its implementations (23)
Map and its implementations (39)
Queue and its implementations (4)
Regular expressions (3)
Design Patterns (75)
Generics (20)
Casting (5)
volatile (13)
Java ThreadLocal (10)
Java Multithreading (113)
Java Multithreading part II (18)
final keyword (13)
static keyword (16)
Java Transactions (JTA) (21)
Concurrent collections (55)
Java Serialization (36)
JDBC (53)
JNDI (17)
RMI (6)
JAXB (10)
JMS (45)
JMX (9)
Servlet Interview Questions (16)
log4j (19)
Annotations (10)
XML (14)
Garbage collection (31)
Programs (8)
JVM (4)
Java8 streams (34)
JavaFX (6)
Autosys Interview questions (21)
The Java Virtual Machine: How and What Is It Used For? (0)
Java 11 (10)
Java 12 (5)
Top Errors You Should Avoid when Studying Programming (0)
Java 17 (1)
JPMS (6)
Java Record Keyword (4)
MapStruct Java Interview questions (0)
Java 21 Interview Questions (46)
Lombok Interview questions (48)
Quarkus Interview questions (50)
Micronaut Interview questions (50)
Java Concurrency and Multi Threading in Java 17 and Java 21 Interview questions (50)
MapStruct Java Interview questions part 2 (50)
Java 17 Garbage Collection Interview Questions (50)
GraalVM Interview questions (50)
Java 21 Coding Standards Interview Questions (50)
Java 21 Virtual Threads Interview questions (50)
Java 21 Collection Framework features Interview questions (50)
JVM Architecture (Java21) Interview questions (50)
Core Java 21 Design Patterns Interview questions (50)
J2EE Design Patterns with Java 21 Interview questions (50)
Azure Virtual Machines (VMs) Interview questions (50)
Azure App Service Interview questions (50)
Azure Kubernetes Service (AKS) Interview questions (50)
Azure Functions Interview questions (50)
Azure Container Instances (ACI) Interview questions (50)
Azure Virtual Desktop Interview questions (50)
Azure Blob Storage Interview questions (50)
Azure Batch Interview questions (50)
Azure Files Interview questions (50)
Microsoft Entra ID Interview questions (50)
Azure Key Vault Interview questions (50)
Microsoft Defender for Cloud Interview questions (50)
Java 21 latest features Interview questions (50)
Java 25 latest features Interview questions (50)
Java 25 Vector API Interview questions (50)
Java 25 Structured Concurrency Interview questions (50)
Difference between Comparable and Comparator interface.
Comparable. Comparator.
Class whose objects to be sorted must implement this interface and to implement compareTo(Object) method. Class whose objects to be sorted do not need to implement this interface. Instead a third class can implement this interface to sort and implement compare method.
Sorting logic must be in same class whose objects are being sorted. Hence this is called natural ordering of objects. Sorting logic is in separate class. Hence we can write different sorting based on different attributes of objects to be sorted.
Collections.sort(List).
Objects will be sorted on the basis of CompareTo method. Collections.sort(List, Comparator).
Objects will be sorted based on the Compare method in Comparator.
Comparable located in Java.lang package. Comparator located in Java.util package.
More Related questions...
Comments & Discussions
Please enable JavaScript to view the comments powered by Disqus.