This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Gareth Diamond
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48394
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
great , i'll give it a go . thanks for the suggestions!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic