aspose file tools*
The moose likes Beginning Java and the fly likes can anyone help to sort list of numbers with letter at the end? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "can anyone help to sort list of numbers with letter at the end?" Watch "can anyone help to sort list of numbers with letter at the end?" New topic
Author

can anyone help to sort list of numbers with letter at the end?

Gareth Diamond
Greenhorn

Joined: Nov 17, 2012
Posts: 2
anyone able to help sort list of 4000 random generated numbers from a file and then write them to a different file?? they are stored as a string and each have
a random letter at the end. here is what i have so far.
any help much appreciated...


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18662
    
    8

Couldn't you just do this:

Put the strings into an ArrayList, instead of writing them to the file.

Sort the ArrayList when you're finished.

And then iterate through the ArrayList and write the strings to the file?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39419
    
  28
Welcome to the Ranch

I have added code tags, which you should always use, and you can see how much better your code looks. Unfortunately the inconsistent indenting (look here for some suggestions) makes it hard to read; you could be missing errors because of mismatched {} pairs. The word string after the import is unnecessary, and the compiler won’t be happy to see it.
Have a look here to find out about sorting objects. Also search for "asciibetical order" before sorting anything with letters in.
You could put all your Strings into a tree set. Go through the first link I gave you and find the “trail”, and you can find out about tree sets. Put the strings all in, not already sorted, and a tree set can sort them for you. Beware. Sets do not support duplicates. You can iterate the set and get them all back ready‑sorted.
Gareth Diamond
Greenhorn

Joined: Nov 17, 2012
Posts: 2
great , i'll give it a go . thanks for the suggestions!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can anyone help to sort list of numbers with letter at the end?