Android ArrayList Calendar add and get is different
Posted
by
Raku ShinShou
on Stack Overflow
See other posts from Stack Overflow
or by Raku ShinShou
Published on 2012-11-10T03:46:52Z
Indexed on
2012/11/10
5:00 UTC
Read the original article
Hit count: 93
I put increment date of the calendar and add into arraylist, but when i loop them out, the date is all same.
Calendar a = Calendar.getInstance();
ArrayList<Calendar> b = new ArrayList<Calendar>();
for (int i=0; i<3; i++) {
a.add(Calendar.DATE, i>0 ? 1 : 0);
b.add(a);
}
for (int i=0; i<b.size(); i++){
Log.d("xxx", "test=" + b.get(i));
}
suppose i wan 10/11/2012, 11/11/2012, 12/11/2012
but it come out like 12/11/2012, 12/11/2012, 12/11/2012
Anyone know how to solve this?
© Stack Overflow or respective owner