Results 1 to 2 of 2
  1. #1
    cassysumandak is offline Member
    Join Date
    Mar 2009
    Posts
    38
    Rep Power
    0

    Default sorting data in txt file

    Hi,

    I've data in txt file with these format:

    UserID:1
    January 20points
    Dec 30points
    March 10 points
    February 10point
    UserID:2
    Feb 10 points
    Dec 10points
    Nov 20points

    How can I sort (ascending)this data with this format:
    UserID:1
    January 20points
    February 10point
    March 10 points
    Dec 30points
    UserID:2
    Feb 10 points
    Nov 20points
    Dec 10points

    I have tried using the collection.sort but it sort my data in a long line.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    One way is to create an array of String that holds your month Strings in order, then store your user data in an ArrayList of a class that hold a month string and the corresponding point. Have this class implement Comparable and in the compareTo method use the String order in the month String array to determine whether one month is higher than the next. Then you can use Collections.sort(...) to sort your array list.

Similar Threads

  1. getting data from a file
    By sugard in forum Advanced Java
    Replies: 2
    Last Post: 03-03-2009, 08:24 AM
  2. Sorting xml file
    By keioGirl in forum Advanced Java
    Replies: 4
    Last Post: 12-12-2008, 06:14 PM
  3. Data Sorting in a .data file using java
    By stutiger99 in forum New To Java
    Replies: 2
    Last Post: 10-08-2008, 03:52 AM
  4. Accessing Data from a .txt file
    By Oasis13 in forum New To Java
    Replies: 5
    Last Post: 02-01-2008, 01:16 AM
  5. Extracting data from an XML file...
    By techno_brains in forum New To Java
    Replies: 1
    Last Post: 07-15-2007, 06:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •