Re: Newbie Question: ArrayLists and Referencing
Taria wrote:
So to reference the number 1 in the the A arraylist would be:
System.out.println ("ArrayList A(0,0) = " +
(ArrayList).get(0).get(0));
Not legal Java. (ArrayList) is a cast, but you apply a dot to it instead of
giving it a variable that points to an ArrayList. You need to do what Chris (
Val ) said:
A.get( 0 ).get( 0 );
Except that "A" as a variable name violates the Sun Java coding conventions.
A variable that is not a constant should have a lower-case first letter in its
name.
and to reference the number 1 in the B arraylist would be:
System.out.println ("ArrayList B(0) = " + Arraylist.get(0));
"Arraylist" isn't spelled correctly. get() is not a static method - you need
an ArrayList instance.
Now, what I want to do is, give ArrayList B the values of the 0th row
Arraylist 1,3,4,2 where ArrayList B (0)=1, ArrayList(1) =3 and so on.
List <List <Foo> > fooMatrix = new ArrayList< ArrayList <Foo>> ();
fillTheMatrix( fooMatrix );
List <Foo> firstRow = new ArrayList<Foo>( fooMatrix.get(0) );
I have tried this:
for ( int i = 0; i < A.get(0).size(); i++ ) {
node.add((ArrayList) data.get(0).get(i));
What is 'data'? By the syntax, it's a primitive, so the cast to ArrayList
will fail.
}
At the node.add I'm getting a 'symbol not found' error. So is this
because the add method doesn't support the reference type I'm passing?
You need to post a *complete* (short) example and the *complete* text (copied
and pasted) of your error messages. Paraphrases are a Bad Idea.
Read and take to heart:
<http://www.physci.org/codes/sscce.html>
--
Lew