Question:
java multidimensional ArrayList?
anonymous
2011-10-17 10:57:25 UTC
[code]
ArrayList> names = new ArrayList>();
names.add(new ArrayList());
names.get(0).add ("name");//where is this line add the "name"?first row first col?
/*i want to add name to the row and last name to the col.like [row]="name";[col]="last name";how i can do that?*/
[/code]
Three answers:
modulo_function
2011-10-17 11:17:07 UTC
There's not such thing as a multi-dimensional array list.



+add

You could experiment. Since arraylists store objects and a consructed array list is an object of the array list class see if you can have an arraylist with array lists as the elements.



I just experimented and these 2 statement compile:

ArrayList alo = new ArrayList();



ArrayList al = new ArrayList();
anonymous
2016-11-14 10:37:21 UTC
Multidimensional Arraylist Java
?
2011-10-17 11:10:17 UTC
well, you should know where name is, if you have a 2 dimensions array, like



String[][] myData = new String[10][2];



then you have 10 rows and 2 columns where column 1 might be your last name and column 2 your first name so let´s add values to it



myData[0][0] = "somelastnam"; //lastname

myData[0][1] = "somefirstname"; //firstname



Edit:



arrays have a set size so you need to know the size if you were told to work with arrays, otherwise is a list, I recommend you reading the java api for LinkedList() http://download.oracle.com/javase/7/docs/api/index.html and setup an implementation for your needs


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...