• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regarding List Issue  RSS feed

 
kittu shusma
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai
i am preparing a timetable for a school in that, i want to print the timings their i got a problem i.e
i have a list which contains timings like 3.45,1.30,8.30,9.30.........................
when i used to display the that list using collection.sort() i am getting output as 1.30...........3.45.........7.30......8.30,9.30...........but
i want output as 8.30,9.30.......1.30...3.45......7.30(as timmings format in timetable).
please can any one solve this problem..........and help me out.........



thanks,
kittushusma.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You have posted in the wrong place; I shall take the liberty of moving this discussion.
We need a lot more details from you. How are you sorting those times? To the sort() method, 8.30 appears to be after 1.00. Have you got an Appointment class which implements the Comparable<Appointment> interface?
 
kittu shusma
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for giving reply..
i am using array for the timmings data and performing some logic
i am sending that timmings array to hashmap
data in hashmap(5.45,12.45,10.45,10.30,8.30,9.30,7.45,2.30,3.45,6.45,4.45, 11.45,3.30,1.30);
after that returning that data to list. in while.............
Iterator itr = hashmapdata.entrySet().iterator();

while (list.hasNext()) {
String str = (String) list.next();

if (str != null && str.length() > 0) {
String courseStr = str.substring(0, str.indexOf(','));
String timminsStr = str.substring(str.indexOf(',') + 1);

if (!timmings.contains(timminsStr)) {
timmings.add(timminsStr);

Collections.sort(timmings);
}
//out.println(timmings);
if (!courses.contains(courseStr)) {
courses.add(courseStr);
Collections.sort(courses);
}
}
}

after sorting this list i got an a list in this format:{1.30,10.30,10.45,11.45,12.45,2.30,3.30,3.45,4.45,5.45,6.45,7.45,8.30,9.30}
but i want times format is:{ 8.30, 9.30, 10.30, 10.45, 11.45, 12.45,1.00, 2.00, 3.00, 3.15, 4.15, 5.15, 6.15, 7.15, 8.15 }
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is really vague. What does “performing logic” mean? What format are those times in? I hope they are not doubles, because
  • 12.00 is greater than 1.00, and ...
  • 10:15 is quarter past ten = 10.25
  • You need to get those times into some sort of Time or Appointment class. If you are going to use the 12-hour clock with am and pm, you need to organise sorting such that 10:00am is less than 9:00pm.
    As I said, Comparable<Appointment> interface.
     
    kittu shusma
    Greenhorn
    Posts: 14
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    in hashmap i have a data like this..........5.45,12.45,10.45,10.30,8.30,9.30,7.45,2.30,3.45,6.45,4.45,11.45,3.30,1.30
    iam sending this data to list(5.45,12.45,10.45,10.30,8.30,9.30,7.45,2.30,3.45,6.45,4.45,11.45,3.30,1.30)
    now i want to arrange and disply the data as 8.30,9.30,10.30,10.45...........1.30,2.30...................6.45 how should i do this explain me a process........


    Hope you got it...........


    Thanks,
    Kittushusma.
     
    Campbell Ritchie
    Marshal
    Posts: 56570
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I have got it, but I don’t think you have. You need to work out for yourself how you are going to get 8:30am to be before 1:00pm. We do not give out the complete answer.
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!