aspose file tools*
The moose likes Beginning Java and the fly likes how to return a string in order? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to return a string in order?" Watch "how to return a string in order?" New topic
Author

how to return a string in order?

C Ho
Greenhorn

Joined: Dec 15, 2002
Posts: 16
I have a string called schedule, for example:

schedule = "^14%Paul's house?Group Meeting\n^9%Nutty Professor's Office?Office Hours\n^12%MegaBits?Lunch"

After breaking it up using StringTokenizer, how do I return it into chronological order?

Return the schedule for each day of the week as a String with the appointments listed in chronological order, starting with those for the first day of the week and ending with those for the last day of the week.
The String should have the following format
Sunday:
^14%Paul's house?Group Meeting
Monday:
^9%Nutty Professor's Office?Office Hours
Tuesday:
^12%MegaBits?Lunch
Wednesday:
xxx
Thursday:
xxx
Friday:
xxx
Saturday:
xxx

xxx is the String representation of the schedule for each day. There should be no newline after the last schedule.
Note: if there are no appointments scheduled for a certain day, then that day should not be included in the String. (For example, if there are no appointments scheduled on Tuesday then:
Tuesday:
xxx

should not be included.)
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
The code that parses the full String could use a StringBuffer to build the final String to return, assuming the input String is in chronological order itself. Your example implied it is, and didn't demonstrate how to show an empty day.

If it's not in order, you can create an intermediate data structure to hold and reorder the appointments. What constitutes an appointment? Write a class to manage that information. You can use the built-in Collection classes (List, Map, Set) to work with your Appointment class.

It will help you more if you try out some techniques, post your code and ask specific questions.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to return a string in order?
 
Similar Threads
Lunch Meetings
How to form a new string out of several old strings excluding some??.......
Does the Future Belong to China?
Biweekly?
How much coffee & sleep?