| Author |
Sort a list
|
Pete Dawn
Greenhorn
Joined: Sep 28, 2006
Posts: 17
|
|
Hi everyone,
I have a list in the following format,
A, B, C, 3
X, Y, Z, 2
J, K, L, 4
P, L, M, 1
Now I need to sort this list based on the 4th index (integer). Can somebody tell me how can I go about it.
I've tried Collections.sort, but it doesnt help me when I have numbers greater than 9, like 10, it puts 1,10... etc.
Thanks.
|
 |
arulk pillai
Author
Ranch Hand
Joined: May 31, 2007
Posts: 3188
|
|
|
Have a look at the Comparable and Comparator interfaces.
|
Java Interview Questions and Answers Blog | Amazon.com profile | Java Interview Books
|
 |
Pete Dawn
Greenhorn
Joined: Sep 28, 2006
Posts: 17
|
|
Can you give me an example. I need to find a quick fix to this one.
Thanks.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Use String.split to get the last digit. Convert it into an integer using Integer.parseInt. Compare on the integer.
I'm sure you can turn this into code.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Sort a list
|
|
|