Lecture Resources
https://github.com/Tiwarishashwat/Jav...
In this lecture, we will deeply understand Comparable and Comparator in Java, which are used to compare and sort objects of user-defined classes.
When working with collections like ArrayList, TreeSet, or Collections.sort(), Java needs a comparison logic — and that’s where Comparable and Comparator come into play.
Topics covered in this video:
Why Comparable and Comparator are needed
Comparable interface in Java
Natural ordering
compareTo() method
Return values and sorting logic
Comparator interface in Java
Custom sorting logic
compare() method
Sorting objects using:
Comparable
Comparator with separate class
Comparator using anonymous inner class
Sorting tricks using subtraction (first - second, second - first)
Multi-level sorting (marks + roll number)
Lambda expressions in Java (Java 8+)
Comparator using Lambda
Cleaner and shorter syntax
With multiple real-world examples and step-by-step explanation, this lecture will help you master object sorting, a very important topic for Java interviews and DSA problems.
This video is part of my Java + DSA course by ShashCode, built for:
Java beginners
College students
Placement & interview preparation
Strong Java Collections fundamentals
👉 Watch till the end to clearly understand when to use Comparable vs Comparator.
Timestamp:
0:00 - Compare Objects
2:30 - Comparable interface
8:43 - Comparator interface
20:38 - Lamba Expression
25:21 - Outro
On this page of the site you can watch the video online Comparable vs Comparator in Java | Sorting Objects | Lambda Expressions Explained with a duration of hours minute second in good quality, which was uploaded by the user ShashCode 07 January 2026, share the link with friends and acquaintances, this video has already been watched 2,038 times on youtube and it was liked by 109 viewers. Enjoy your viewing!