| Author |
Sorting ArrayList with Comparitor Interface for String property
|
Komari raj
Ranch Hand
Joined: Dec 12, 2008
Posts: 43
|
|
Hi All
Hi I have list of Beans with 3 proprties of Employee Bean(name, age, address) .
I have Taken Address comparator Class shown in below.
Output I am getting is:
Address: 12-3-hyd Age: 25 Name: XXX
Address: 45-KKD Age: 23 Name: YYY
Address: AD Road-Delhi Age: 56 Name: aaa
Address: BRRoad-Delhi Age: 45 Name: bbb
here my requirement is....
I want to display sort beans as per Address like below..
Address: AD Road-Delhi Age: 56 Name: aaa
Address: BRRoad-Delhi Age: 45 Name: bbb
Address: 12-3-hyd Age: 25 Name: XXX
Address: 45-KKD Age: 23 Name: YYY
That comparior Interface is first preference given to numbers only...but i want write comparitor class for giving first preffs to strings...
|
 |
Andrey Kozhanov
Ranch Hand
Joined: Mar 12, 2010
Posts: 79
|
|
Just put necessary functionality in your AddressComparator class. For example if address is a String, it could be written like this:
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3865
|
|
|
That might work - it depends on what is needed. For instance, that would have 199-XXX come before 1AA-AAA, because it would use alphabetical sorting on the second digit. Whether that is OK depends on the exact requirement (but I suspect it isn't).
|
 |
Komari raj
Ranch Hand
Joined: Dec 12, 2008
Posts: 43
|
|
Andrey Kozhanov wrote:Just put necessary functionality in your AddressComparator class. For example if address is a String, it could be written like this:
Hi Andrey Kozhanov
Thank you very much..
As my requirement it is ok..
Regards
Raju.Komari
|
 |
 |
|
|
subject: Sorting ArrayList with Comparitor Interface for String property
|
|
|