I want to create 3 ArrayLists from some arrays like below:
([x,y]) ([x1,y1],[x2,y2],[x3,y3]) ([m1,n1],[m2,n2],[m3,n3],[m4,n4],[m5,n5])
Here is the code related to this part:
public static ArrayList<Double[]>[] hexpos = (ArrayList<Double[]>[])new ArrayList[3];
for (int i = 0; i < 3; i++)
hexpos[ i ] = new ArrayList<Double[]> ();
//====================initial arraylist1
Double[] t = new Double[2];
t[0]=x;
t[1]=y;
hexpos[0].add(t);
System.out.println("xtest"+ hexpos[0].get(0)[0]);
System.out.println("ytest"+ hexpos[0].get(0)[1]);
//======================== initial arraylist2
int count=1;
t = new Double[2];
t[0]=x;
t[1]=y-(2*r);
hexpos[count].add(t);
t = new Double[2];
t[0]=x+(3*s/2);
t[1]=y-r;
hexpos[count].add(t);
t = new Double[2];
t[0]=x+(3*s/2);
t[1]=y+r;
hexpos[count].add(t);
count++;
//======================== initial arraylist3
t = new Double[2];
t[0]=x;
t[1]=y-(4*r);
hexpos[count].add(t);
t = new Double[2];
t[0]=x+(3*s/2);
t[1]=y-(3*r);
hexpos[count].add(t);
t = new Double[2];
t[0]=x+(3*s);
t[1]=y-(2*r);
hexpos[count].add(t);
t = new Double[2];
t[0]=x+(3*s);
t[1]=y;
hexpos[count].add(t);
I just print out the first arraylist as an example: The output is: xtest 400 ytest 400 xtest 400 ytest 400 xtest 400 ytest 400 The problem is that why it repeats 3times!!!
x
,y
,s
andr
? – JavaDev Jan 10 '14 at 8:19