**Initial Format saved as a text document:**
04
05 10 25 40 55
06 05 15 25 35 45 55
07 00 05 10 15 20 25 30 35 40 45 50 55
08 00 05 10 15 20 25 30 35 40 45 50 55
09 00 05 10 15 20 25 30 35 40 45 50 55
10 00 05 10 15 20 25 30 35 40 45 50 55
11 00 05 10 15 20 25 30 35 40 45 50 55
12 00 05 10 15 20 25 30 35 40 45 50 55
13 00 05 10 15 20 25 30 35 40 45 50 55
14 00 05 10 15 20 25 30 35 40 45 50 55
15 00 05 10 15 20 25 30 35 40 45 50 55
16 00 05 10 15 20 25 30 35 40 45 50 55
17 00 05 10 15 20 25 30 35 40 45 50 55
18 00 05 10 15 20 25 30 35 40 45 50 55
19 00 05 10 15 20 25 30 35 40 45 50 55
20 00 05 10 15 20 25 30 35 40 45 50 55
21 05 15 25 40 55
22 10 25 40 55
23 10 25 40 55 55
00 10 25 40 55
01 17 47
02 17 47
03 17 47
**Desired result should look like this:**
05:10 05:25 05:40 05:55
06:05 06:15 06:25 06:35 06:45 06:55
07:00 07:05 07:10 07:15 07:20 07:25 07:30 07:35 07:40 07:45 07:50 07:55
08:00 08:05 08:10 08:15 08:20 08:25 08:30 08:35 08:40 08:45 08:50 08:55
09:00 09:05 09:10 09:15 09:20 09:25 09:30 09:35 09:40 09:45 09:50 09:55
10:00 10:05 10:10 10:15 10:20 10:25 10:30 10:35 10:40 10:45 10:50 10:55
11:00 11:05 11:10 11:15 11:20 11:25 11:30 11:35 11:40 11:45 11:50 11:55
12:00 12:05 12:10 12:15 12:20 12:25 12:30 12:35 12:40 12:45 12:50 12:55
13:00 13:05 13:10 13:15 13:20 13:25 13:30 13:35 13:40 13:45 13:50 13:55
14:00 14:05 14:10 14:15 14:20 14:25 14:30 14:35 14:40 14:45 14:50 14:55
15:00 15:05 15:10 15:15 15:20 15:25 15:30 15:35 15:40 15:45 15:50 15:55
16:00 16:05 16:10 16:15 16:20 16:25 16:30 16:35 16:40 16:45 16:50 16:55
17:00 17:05 17:10 17:15 17:20 17:25 17:30 17:35 17:40 17:45 17:50 17:55
18:00 18:05 18:10 18:15 18:20 18:25 18:30 18:35 18:40 18:45 18:50 18:55
19:00 19:05 19:10 19:15 19:20 19:25 19:30 19:35 19:40 19:45 19:50 19:55
20:00 20:05 20:10 20:15 20:20 20:25 20:30 20:35 20:40 20:45 20:50 20:55
21:05 21:15 21:25 21:40 21:55
22:10 22:25 22:40 22:55
23:10 23:25 23:40 23:55 23:55
00:10 00:25 00:40 00:55
01:17 01:47
02:17 02:47
I have stored the file to an arrayList but would like to manipulate things to get the desired format? Any suggestions/help is highly appreciated. This is what i have written so far.
package TestPaket; import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.Scanner; public class BustimeTable { private static ArrayList<Time> timesArray = new ArrayList<Time>(); public static void main(String[] args) { Scanner scanner = null; try { File file = new File("C:/Users/Tommy/workspace/Prov/SLtid.txt"); scanner = new Scanner(file); while(scanner.hasNextLine()){ String[] tokens = scanner.nextLine().split("\\s+"); for (int i= 0; i< tokens.length; i++) { Time t = new Time(tokens[i], tokens[i].substring(01)); // new time ( hour, minute ) System.out.println(t); } }} catch (Exception e) { e.printStackTrace(); }}}
I have another class called the time class that basically sends the hour and minutes to the main class: