i have an arrylist and a list view.i need to bind the arraylist to listview. is there 2 dimensional arraylist in java. if so,how to bind datas in arraylist.How to bind it in a JTable
5 Answers
JTable know two kinds of 2D Arrays Object [][]
or Vector<Vector<Object>>
that are directly accesible, some examples about JTable

- 109,525
- 20
- 134
- 319
-
+1 Is this characteristic of the [`DefaultTableModel`](http://download.oracle.com/javase/6/docs/api/javax/swing/table/DefaultTableModel.html)? – trashgod Jun 20 '11 at 07:13
-
yes or no too, I never see some differencie between set Array/Vector, to the myTable (data[][], header[]) or standard way to stick Abstract/DefaultTableModel, by permormance issue (my view) I'm not fans for Set or List family wraped into TableModel, +1 :-) – mKorbel Jun 20 '11 at 07:52
Java supports multi-dimensional data structures such as List<List<…>>
. ArrayList
is just one implementation of the List
interface, and each dimensions may use a different implementation. This example illustrates List<List<Integer>>
.
The two dimensional case may require nothing more elaborate than List<Record>
, shown here; or List<Value>
, shown here in the context of an AbstractTableModel
. See Creating a Table Model for additional details.
-
ArrayList
arl = new ArrayList – KIRAN K J Jun 20 '11 at 09:01();.....Object obj = arl.clone();.... final JTable table = new JTable(data, obj); give an error -
@KIRAN: I don't understand your code. What error? You might update your question with an [sscce](http://sscce.org); code in comments is hard to read. I see both @camickr and @Catalina Island addressed your binding question. – trashgod Jun 20 '11 at 16:45
...is there 2 dimensional arraylist in java... - Yes
// T is the type of your data.
List<ArrayList<T>> list = new ArrayList<ArrayList<T>>();
UPDATE
To use the data from the ArrayList
in the JList
you need to convert it to an array of objects. For example:
JList jlist = new JList(list.toArray());

- 10,217
- 9
- 62
- 88
how to bind it in listview
JList
has a AbstractListModel
that works a lot like how JTable
has a AbstractTableModel
. If that's what you want, the examples in "How to Use Lists" may help.

- 7,027
- 2
- 23
- 42
I don't know what a "listview" is. But if you want to display data from an ArrayList in a JTable then you need to create a custom TableModel. List Table Model is one implementation that you can use.

- 321,443
- 19
- 166
- 288