whats the best way to sort this plain text file in java?

Discussion in 'OT Technology' started by D1G1T4L, Dec 23, 2003.

  1. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    sample plain text file
    Code:
    Digital+DIG+911+411+OT 430th street+92321+OTland+none+February+2+1909+
    Nocera+Nocera11+n/a+n/a+n/a+n/a+n/a+n/a+April+22+1939+
    
    whats the best way to sort it by 1st field

    also whats the best way to sort it by Month and then Day (field number 9 and 10)
     
  2. Nocera

    Nocera ...

    Joined:
    Aug 9, 2000
    Messages:
    1,307
    Likes Received:
    0
    Location:
    Long Island, NY
    :squint: why do i see my name?
     
  3. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    Parse it into a data structure (looks like maybe a Person object?) and sort it from there.
     
  4. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area

    :squint:
     
  5. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    k i will write a People class that will hold every element from each line and then a Sorting Class which will sort by any field i choose
     
  6. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    Make a people object that has a private attribute for each element above and gets/sets for each. Then write a group class (maybe you have something better to describe the collection of people objects you have, i dunno) which has an attribute of an array of people objects. Inside of the group class write a method that sorts the array based on an attribute name. That would make for a decent oop assignment.
     
  7. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area

    :cool:
     
  8. beaniemak

    beaniemak New Member

    Joined:
    Nov 27, 2000
    Messages:
    390
    Likes Received:
    0
    Create that person object like CM suggested and then create a Comparator object that compares the first field of that file. Then put those Person objects into a TreeSet object that you create with your PersonComparator object and it'll magically sort it all for you.

    Something like this would make a good C++ project, but since Java does alot of the hard work for you it kinda becomes easy.
     

Share This Page