-
java newbie... sort array
How do I sort an array of "-" delimited numbers?
The array will contain numbers like this:
0-471-34609-8
0-13-031997-X
.
.
.
Any clue on how I can sort that?
thanks,
Paul
-
nevermind... I'm real new w/ java...
java.util.Arrays.sort(myArray);
-
Hi,
one option is to read the numbers like string and remove "-" from it and convert it back to numbers and sort (like ordinary numbers).
The other option if format is fixed for all numbers is to look at the first part of the number and compare i.e if the numbers are
0-471-34609-8
1-13-031997-6
Then comapring the first digit (0 & 1) yields the order regardless of the remaining digits. If the first digit is same then go to the second one and so on till order is sorted out but beware if the format is not fixed then it will not work e.g
*- 471-34609-8
1-13-031997-6
in this case since the format is different the second number though bigger may end up as a smaller number in comparison.
bye
Pankaj
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks