Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Assign value to arraylist

807599Jan 18 2007 — edited Jan 18 2007
Hi everyone, I am new to Java.

Sth weird here:
ArrayList<ArrayList <Integer>> oneItem = new ArrayList<ArrayList <Integer>>();
ArrayList<ArrayList <Integer>> kItem = new ArrayList<ArrayList <Integer>>();
ArrayList<Integer> temp1 = new ArrayList<Integer>();
ArrayList<Integer> temp2 = new ArrayList<Integer>();
ArrayList<Integer> temp3 = new ArrayList<Integer>();
.
.
.
.
.
.
for(int i=0;i<oneItem.size();i++)
{
temp1 = (ArrayList)oneItem.get(i);
for(int j=i+1; j<oneItem.size();j++)
{
temp2 = (ArrayList)(oneItem.get(j)); //temp2=static
temp3.add(temp1.get(0));
temp3.add(temp2.get(0));
kItem.add(temp3); //I suppose to get an arraylist of arraylist like[[1,2],[4,5]....],but I got [[],[],[],....]].
temp3.clear();
}
}

I can't get the intended value for kItem but an arraylist of arraylist with no value in it? where is the mistake of my program?
Thanks in advance.

Message was edited by:
microX

Message was edited by:
microX
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 15 2007
Added on Jan 18 2007
5 comments
252 views