-2
我想創造一些陣列3周的ArrayList像下面創建的ArrayList從陣列
public static ArrayList<Double[]>[] hexpos = (ArrayList<Double[]>[])new ArrayList[3];
for (int i = 0; i < 3; i++)
hexpos[ i ] = new ArrayList<Double[]>();
// ====== ==============初始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]);
// ========================初始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++;
// ========================初始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);
我剛打印出來的第一數組列表作爲一個例子: 輸出結果爲: xtest 400 ytest 400 xtest 400 ytest 400 xtest 400 ytest 400 問題是爲什麼它重複3次!!!
什麼是你有多大?你期望的輸出是什麼?你得到的輸出是什麼? – neoprez
你是什麼意思「第一次召3次會員」?你確定?您能向我們展示您使用它的環境嗎? –
Thx對於這種回覆,我添加了更多的代碼細節並輸出到帖子中! – user3180204