Skip to Main Content

Java Programming

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!

Multidimensional ArrayList - Set method syntax

807589Oct 10 2008 — edited Oct 10 2008
What is the correct syntax for changing the value of a specified row/column in an ArrayList?
ArrayList matrix = new ArrayList();

matrix.add( new ArrayList() ) ;
((ArrayList)matrix.get(0)).add("row 0 col 0");
((ArrayList)matrix.get(0)).add("row 0 col 1");
((ArrayList)matrix.get(0)).add("row 0 col 2");

matrix.add( new ArrayList() ) ;
((ArrayList)matrix.get(0)).add("row 1 col 0");
((ArrayList)matrix.get(0)).add("row 1 col 1");
((ArrayList)matrix.get(0)).add("row 1 col 2");

matrix.add( new ArrayList() ) ;
((ArrayList)matrix.get(0)).add("row 2 col 0");
((ArrayList)matrix.get(0)).add("row 2 col 1");
((ArrayList)matrix.get(0)).add("row 2 col 2");

 // HELP WITH SYNTAX
matrix.set(2,2,"hello") ;

System.out.println( (String)((ArrayList)matrix.get(2)).get(2) ) ;
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 7 2008
Added on Oct 10 2008
3 comments
2,422 views