This code gives ArrayIndexBoundExcpetion ,but if in for loop ,i write d.length it works correctly.
I have no of 5,4 elements in key,value pair.
I really couldnt get why it is so .Should work same in both way.
import java.util.Map;
import java.util.TreeMap;
public class TreeMapDemo1 {
Map calendar=new TreeMap();
TreeMapDemo1(
String d[],String e[])
{
for(int i=0;i<e.length;i++) //with d.length ,works
{
calendar.put(d[i],e[i]);
}
}
public static void main(String args[])
{
String dates[]={"22/10/1974","19/02/2005","22/1122005","29/11/2006"};
String events[]={"Birthday","Anniversary","Marriage","Thankgiving","Independ"};
TreeMapDemo1 tmd=new TreeMapDemo1(dates,events);
System.out.println(tmd.calendar);
}
}