I had a small query regarding the following
When sorting the following values by .sort() it is not displaying the values in ascending order i.e
it is taking 10 as 1 and displaying 10 first rather than 2
s1="BS EN 60704-2-10:2002";
s1="BS EN 60704-2-2:2003";
Thanks in Advance
Originally posted by sai prasanna:
but the values are in different format as follows then also should i write my own comparator
BS EN 60704-1:1995
BS 1016-104.4:1998, ISO 1171:1997
BS 2782-3:Method 323B:1996, ISO 6721-5:1996
thanks in advance
Yes. If the standard String compare method doesn't give you the ordering you want then write a Comparator that does.
How about this for the custom method:
- Try converting the given element in each array to an int. If neither conversion throws a NumberFormatException, compare the two ints; else compare them as strings.
As soon as a comparison provide a lt, eq, gt decision you're done. If all corresponding parts are equal and neither array has extra pieces, the two are equal.
Note: This would ignore differing puncuation/spacing. "BN 123" would be equal to "BN:-:===123". To change this you could include Strings of delimiters in your array. For instance, those two might be "BN", " ", "123" and "BN", ":-:===", "123".
STANDARD NOTE ABOUT equals() AND hashCode():
If you create a custom class for these numbers and override the equals() method, make sure that hashCode() returns equal ints for any two objects that are equal. i.e. if a.equals(b) then a.hashCode() had darn well better == b.hashCode().
[ September 07, 2006: Message edited by: Ryan McGuire ]