java question sorting/etc

Discussion in 'OT Technology' started by D1G1T4L, Aug 12, 2003.

  1. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    i have data in text file
    something like
    name:address:etc

    i want load the data into my program but sort it by name

    whats the best way to do this?

    any suggestions, comments, anything.....
     
  2. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    Smart ass answer: put it in a database!

    I've been using the HashMap for a lot of my data structure trickery. I know there's a way to sort on it. I've read the section in my one Java book but the book is at work (right next to hashmaps and iterators - but I skipped over it since my sorting takes place at the database level). The book recommended not sorting too often because it can be a healthy performance hit. Maybe check out iterators and or hashmaps (I'm thinking hashmaps).

    If you're still stuck, contact me on IM tomorrow and I'll hook you up...
     
  3. D1G1T4L

    D1G1T4L Active Member

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

    no database is a no no because this program will be distributed to many users and it wont be practical to make them all install database drivers etc or whatever
     
  4. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    yes hashmap is pretty good idea.....
    i had it somewhere in my book too but i dont think they explained it well (in terms of sorting)

    i shall look into it
     
  5. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
  6. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    I believe Java already has a sorting algorithm implemented so its plug and play/pray. No comp. sci. experience necessary. Although implementing a list/bubble/insertion sort is always fun and not very painful at all.
     
  7. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,278
    Likes Received:
    555
    Java should have quicksort built into the library.

    What you'll have to do is read in each line, split it into its constituent fields, and sort on the field you want, then swap whole entries instead of just individual fields.
     
  8. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    Man, I need to do some real programming again. I got a 5 on AP Comp. Sci. AB, but since I haven't done any of it in months I hardly remember all the sorting/searching/hashing algorithms :(
     
  9. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    yea i read each line with BufferReader then split it using StringTokenizer after i sort it though, how should i swap whole enteries though

    I am thinking of creating an object for each entry, then sorting based on the name and then displaying it
     

Share This Page