• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...


 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
great , i'll give it a go . thanks for the suggestions!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic