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
На этой странице сайта вы можете посмотреть видео онлайн Comparable vs Comparator in Java | Sorting Objects | Lambda Expressions Explained длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь ShashCode 07 January 2026, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 2,038 раз и оно понравилось 109 зрителям. Приятного просмотра!