Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-12-2009, 03:49 AM
Member
 
Join Date: Mar 2009
Posts: 38
Rep Power: 0
cassysumandak is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 04-12-2009, 04:02 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,391
Rep Power: 8
Fubarable is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT +2. The time now is 06:38 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org