So here's what I have right now:
public static void main(String[] args) {
Calendar[][] times = new Calendar[10][2];
Calendar begin = Calendar.getInstance();
for(int i = 0; i < 10; i++) {
times[i][0] = begin;
begin.add(Calendar.MINUTE, 120);
times[i][1] = begin;
}
for(int i = 0; i < 10; i++) {
System.out.println("Start time:" + times[i][0].getTime() + " and end time is: " + times[i][1].getTime());
}
}
To my understanding of how add works in the Calendar class, I would expect that times[0][0] would be time of compilation, times [0][1] would be 120 minutes in the future. Next run through the loop times[1][0] would equal times[0][1] and times[1][1] would be 120 minutes ahead of that. Is that incorrect? It currently outputs the same time for each member of the array.
EDIT: Thanks for the help everyone, here's the correct code:
public static void main(String[] args) {
Calendar[][] times = new Calendar[10][2];
Calendar begin = Calendar.getInstance();
for(int i = 0; i < 10; i++) {
times[i][0] = (Calendar) begin.clone();
begin.add(Calendar.MINUTE, 120);
times[i][1] = (Calendar) begin.clone();
}
for(int i = 0; i < 10; i++) {
System.out.println("Start time:" + times[i][0].getTime() + " and end time is: " + times[i][1].getTime());
}
}