Link to home
Start Free TrialLog in
Avatar of swp3h6
swp3h6

asked on

Sorting entries in a text file

my problem goes like this:

I have a text file filled with entries that each have a category name and delimiter in front of them, kindof like the following:

Category1::blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah

Category2::blahblahblahblahblahblahblahblahblahblahblahblahblahblahblah blahblahblahblahblah blahblahblahblahblah

Category1::blahblahblahblahblahblahblahblahblahblahblahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah

and so forth....


I'd like to sort these entries by their categories and print the results to a new text file like this:

Category1

     blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah

blahblahblahblahblahblahblahblahblahblahblahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah blahblahblahblahblah

Category 2

     blahblahblahblahblahblahblahblahblahblahblahblahblahblahblah blahblahblahblahblah blahblahblahblahblah

====================================

what would be the easiest way to do this?

     
 
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
is this homework?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of swp3h6
swp3h6

ASKER

okay, i'll try these things out.  

And no its not homework, just work.
StringList sl = new StringList();
sl.read("x.txt");
Collections.sort(sl);
sl.save("sorted-x.txt");
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of swp3h6

ASKER

Thanks for all the input everyone, but I never got any kind of Collections thing to work for me.  I solved the problem by using a 2 dimentional array to sort the entries by category.
That is also possible, but using Collections, you prevent writing a lot of code because you wil use the in-built API :)