I am trying to build a map with time starting from 06.00 to 23:59 as keys and I will keep track of a number for each time as value.I need the time to stored HH.mm as format and I am planning to build the map using a loop by incrementing one minute and run the following code inside the loop.The problem here is since I have to set the format as HH.MM strictly I have to get the input as String and format it and then parse it back as double which affects the perfomance.Is there a global setting to change so that whatever double number I choose in this particular class should be of the format ##.##.Also point here to note is since it is time it ends at 60 minutes and hence I have to break the current iteration with the help of .6.
Map map = new LinkedHashMap();
//Edit:Moved DecimalFormat Outside the loop
DecimalFormat df = new DecimalFormat("##.##");
for (double time= 06.00; time<= 22.00; time= time+ 01.00)
{
String timeString = df.format(appointmentTime);
time = Double.parseDouble(timeString);
if (timeString.indexOf(".6") != -1)
{
time= time+ 00.40;
}
map.put(time,"<number>");
}
I beliI believe you choose the most complicated approach. Instead of iterating the time variable you could iterate a simple number indicating the minutes since 0 o’clock and then generate your time double only for the map.
But I believe (I do not understand your question in that point), it would be better not to use a double for the map key, instead you could use your own Time class, something like: