now, it is working fine for me.
i have modified my code to
Now, sorting is proper. Thanks a lot.
Wouter Oet wrote:Why don't you want to use a Comparator?
I had two options either to convert String to Integer and sort or use comparator and pass as an argument to Collections.sort() method. So, i thought converting String to Integer is easier than creating a comparator.
Please correct me if i am wrong.
To use a Comparator<Foo> you would have to work out in which order you are going to sort Foo. You can have several Comparators<Foo>, with different sorting.
Start with pencil and paper, and eraser (when I go to lectures I carry a big eraser which looks as if it would cause real injury if I threw it at a student and I say that eraser is their most important piece of hardware).
Write down how you ought to sort your Foo.
Remember that String and Integer already implement Comparable<String> and Comparable<Integer> and there is a Comparator<String> inside the String class ready for you to use. So you may not need Comparators there.
When you have written how to sort your Foo, covert that to code and put it in the Comparator<T>#compare(T, T) method, in a class which implements Comparator. You can forget about the equals() method.
Pass an object of that Comparator to any sort() method you are using.
Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
a bit of art, as a gift, the permaculture playing cards