My question is how to sort a javabean on the basis of two fields.
I have to create a javabean and then sort it by some String type field and then by another String type field.When I sort it for the second time the sorted sequence of the first field should not change and I have to use the ArrayList for
it.I have used comparator here but when I sort it the sorted sequence of the first field changes.
Please help me .
Initially I want to create a javabean whose parameters are name and some type, both are strings .I have to sort the bean first using the type field and then by name. when Iam sorting it by name the sequence of type also changes,this should not happen.I want to use the logic of order by clause of sql as the following:
Company OrderNumber
ABC Shop 5678
Sega 3412
Ws 6798
Ws 2312
Company OrderNumber
ABC Shop 5678
Sega 3412
Ws 2312
Ws 6798
Here I want to use ArrayList.Is it advisable to use the ArrayList.
My code is:
This is the output:
before sorting
Check:name1
Create:name2
Attempt:name3
After sorting by Type
Attempt:name3
Check:name1
create:name2
after sorting by name
Check:name1
create:name2
Attempt:name3
Here After sorting by name order of type should not change.
Thanks & Regards,
Anitha Tolgiri