Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Viktor Kubinec wrote:First of all, you should follow java naming conventions ( class names should start with uppercase letter).
Second, your compareTo method implementation is not right (it is legal, but incorrect)
try this :
or this :
in compareTo method you should compare "this" object with s object. In your implementation you are comparing this object with itself, which makes no sense. To get a proper output you have to override toString method.
Abhishek Bose wrote:
Thanks a lot... but i am still confused with how its working
Abhishek Bose wrote:
Thanks a lot... but i am still confused with how its working
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Jeff Verdegan wrote:
Abhishek Bose wrote:
Thanks a lot... but i am still confused with how its working
What are you confused about. It's a method. It gets called. And, as the docs say, it returns negative, 0, or positive, to indicate that s.songName is less than, equal to, or greater than this.songName. (Which, by the way, is backwards for how one normally implements a comparison, but maybe somebody is doing a reverse sort.)
So what's your confusion?
Abhishek Bose wrote:
Jeff Verdegan wrote:
Abhishek Bose wrote:
Thanks a lot... but i am still confused with how its working
What are you confused about. It's a method. It gets called. And, as the docs say, it returns negative, 0, or positive, to indicate that s.songName is less than, equal to, or greater than this.songName. (Which, by the way, is backwards for how one normally implements a comparison, but maybe somebody is doing a reverse sort.)
So what's your confusion?
According to my understanding in the first cycle this.songName gets value fastcar and s.songName gets the value falltopieces and then they get compared?