compareTo() hands-on | sorting custom objects in java [LOGIC] | Comparable |#5

Share this & earn $10
Selenium Express
Published at : 06 Dec 2020
4860 views
127
2

In this video, we will learn about working with compareTo(). The compareTo() which is present inside the comparable interface returns 3 types of value eg. A +ve, -ve or a zero. The compareTo() used by the sort() to sort any kind of object.

As we have seen already, The Integer class and String class already has overridden the compareTo() and given there implementation like all other wrapper classes. Now we have to build a compareTo() for our song class to make it eligible for sorting. We can sort the song objects based on various property like an artist, song title track or by the release year.

So let’s dive in and explore the compareTo() method of comparable interface and sort some customize objects. Do remember that it is one of the most important interview question that you need to prepare.

For more videos in the collection framework, consider subscribing by clicking the link below.

https://www.youtube.com/channel/UCpUYkSDJpHug-vfC5S-NXRA?sub_confirmation=1

Stay tuned and like my Facebook page for more.

https://www.facebook.com/seleniumexpress

You can write your unsolved query to seleniumexpress@gmail.com.

Music :
-----------
credits : -
(intro)
Adventures by A Himitsu https://soundcloud.com/a-himitsu
Creative Commons — Attribution 3.0 Unported— CC BY 3.0
http://creativecommons.org/licenses/b...
Music released by Argofox https://youtu.be/8BXNwnxaVQE
Music provided by Audio Library https://youtu.be/MkNeIUgNPQ8


intro template :
www.youtube.com/Alexbau01
comparable and comparator in javasort method in javacollections.sort java

Harold Velazquez x Ariel Kelly - Actívate (Video Oficial)

Harold Velazquez x Ariel Kelly - Actívate (Video Oficial)

SIMI - CITY LIGHTS (Visualiser)

SIMI - CITY LIGHTS (Visualiser)

Game of Thrones - Best Scenes Compilation HD

Game of Thrones - Best Scenes Compilation HD

Metallica: ...And Justice for All and Turn the Page (MetOnTour - Istanbul, Turkey - 2014)

Metallica: ...And Justice for All and Turn the Page (MetOnTour - Istanbul, Turkey - 2014)

Will your crush ever like you?  (Accurate) | Mister Test

Will your crush ever like you? (Accurate) | Mister Test

an indie song but it's in vietnamese

an indie song but it's in vietnamese

Haux - Seaside (Official Music Video)

Haux - Seaside (Official Music Video)

三浦大知 (Daichi Miura) / Blizzard (映画『ドラゴンボール超 ブロリー』主題歌)

三浦大知 (Daichi Miura) / Blizzard (映画『ドラゴンボール超 ブロリー』主題歌)

Millie Bobby Brown - Why People Hate Her So Much? - Stranger Things 2018

Millie Bobby Brown - Why People Hate Her So Much? - Stranger Things 2018

There Often Is a Morning After

There Often Is a Morning After

TOP 5 Planes Which Can Fly The Highest Altitudes

TOP 5 Planes Which Can Fly The Highest Altitudes

Learn English  - You're welcome / My pleasure

Learn English - You're welcome / My pleasure

Adaptation.

Adaptation.

Peter Brown - They Only Come Out At Night Original 12 inch Version 1984

Peter Brown - They Only Come Out At Night Original 12 inch Version 1984

Ella Mai - Anymore (Audio)

Ella Mai - Anymore (Audio)

4 year old Mila is very Single...as it should be!!

4 year old Mila is very Single...as it should be!!

The Most Ambitious "Open-World" Game Yet...

The Most Ambitious "Open-World" Game Yet...

Vitamin E Oil Skin Treatment |Get Beautiful, Spotless, glowing Skin

Vitamin E Oil Skin Treatment |Get Beautiful, Spotless, glowing Skin

Tutorial #68 Strong and Weak links and Open Ended Chains, which enable you to remove small numbers.

Tutorial #68 Strong and Weak links and Open Ended Chains, which enable you to remove small numbers.

Rocky Handsome John abraham Fight scene with knife

Rocky Handsome John abraham Fight scene with knife

How to STAY PROTECTED from COVID-19 - Coronavirus

How to STAY PROTECTED from COVID-19 - Coronavirus

9 Models on the Pressure to Lose Weight and Body Image | The Models | Vogue

9 Models on the Pressure to Lose Weight and Body Image | The Models | Vogue

Lil Mosey - Noticed (Lyrics)

Lil Mosey - Noticed (Lyrics)

House Owner - Official Making Video | Kishore, Sriranjani, Lakshmy Ramakrishnan

House Owner - Official Making Video | Kishore, Sriranjani, Lakshmy Ramakrishnan

Duck pond construction -**IN most SIMPLE & EASIEST-** Less EXPENSIVE Way

Duck pond construction -**IN most SIMPLE & EASIEST-** Less EXPENSIVE Way

Michael Jackson - The Way You Make Me Feel and Man In The Mirror 30th Annual Grammy 1988

Michael Jackson - The Way You Make Me Feel and Man In The Mirror 30th Annual Grammy 1988

Ang feeling na crush ka din ng crush mo / Part 3

Ang feeling na crush ka din ng crush mo / Part 3

Consultation Room

Consultation Room

Why I am the BEST SAGE in Valorant

Why I am the BEST SAGE in Valorant

Backstreet Boys - The One (Official Video)

Backstreet Boys - The One (Official Video)

AS Law Lecture: Delegated Legislation (1)

AS Law Lecture: Delegated Legislation (1)

Anything 6 Year Old Everleigh Can Carry, We'll Pay For!!! - Challenge

Anything 6 Year Old Everleigh Can Carry, We'll Pay For!!! - Challenge

Donald Trump 2024? Why he may run again

Donald Trump 2024? Why he may run again

Answer 21 (Yes, they are. No, they aren't.)

Answer 21 (Yes, they are. No, they aren't.)

My 2021 Bullet Journal Setup

My 2021 Bullet Journal Setup

When Elon Musk Realized China's Richest Man Is A Dope (Jack Ma)

When Elon Musk Realized China's Richest Man Is A Dope (Jack Ma)

Send emails in Spring Boot apps [Intermediate Spring Boot]

Send emails in Spring Boot apps [Intermediate Spring Boot]

Lars Bak - The Making of a Secure and Robust IoT Development Platform

Lars Bak - The Making of a Secure and Robust IoT Development Platform

Lyrics | 45 | Shinedown

Lyrics | 45 | Shinedown

[세상에서 가장 쉬운 영어] 36강 Would you like 로 주문해요

[세상에서 가장 쉬운 영어] 36강 Would you like 로 주문해요

HOW TO BAKE A MOIST CHOCOLATE CAKE WITHOUT AN OVEN | SPRINKLEOFSASS

HOW TO BAKE A MOIST CHOCOLATE CAKE WITHOUT AN OVEN | SPRINKLEOFSASS

Outdoor Nativity Sets - Our Story

Outdoor Nativity Sets - Our Story

Fallacious Commercial?

Fallacious Commercial?

PCS क्या होता है? PCS की तैयारी कैसे करें? पीसीएस अधिकारी कैसे बनें || How to become PCS Officer

PCS क्या होता है? PCS की तैयारी कैसे करें? पीसीएस अधिकारी कैसे बनें || How to become PCS Officer

GENTS - Emotional Facelift

GENTS - Emotional Facelift

Stop Worrying About the Future - Short Sermon

Stop Worrying About the Future - Short Sermon

Crazy Karens Who Already Ruined 2021

Crazy Karens Who Already Ruined 2021

РАМАЗАН ПРИСЕДАЕТ 400

РАМАЗАН ПРИСЕДАЕТ 400

Nastya and a funny story about a sleeping dad

Nastya and a funny story about a sleeping dad