tags:

views:

50

answers:

3

I want to return arraylist of one table data out without using Bean/Transfer objects

ArrayList<MyBean> list = new ArrayList<myBean>();

not like above, because I dont have such MyBean Class in my application, but still i need to add each row of employee table to ArrayList

How can I do this ?

A: 

Are you by any chance looking for Arrays.asList(), javadoc here.

Returns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.) This method acts as bridge between array-based and collection-based APIs, in combination with Collection.toArray. The returned list is serializable and implements RandomAccess.

Bakkal
Thirst for Excellence
A: 

List list = Arrays.asList(table);

Joni
Thirst for Excellence
A: 

If you are talking about a JTable you have to pass through the model to obtain the data you need. But it won't be so straightforward since the only method you have for sure is getValueAt(int row, int col) that is not efficient to retrieve the whole list of elements of the table.

Usually you don't use just a DefaultTableModel but a custom one that must has a way to keep track of the list of employees for sure..

In other case you will have to wrap all the column values for a row inside an object (also if you don't have any MyBean class object) or use a composite object, otherwise it would be just crazy.

Jack
Thirst for Excellence
So you are asking if in a full object oriented programming language in which everything is an object at the point that also your `main` method must be contained in an object you are allowed to use an `ArrayList` of "non-objects"? __No__, that's not possible.. I don't really see how you could avoid using objects, you could use an `ArrayList` of `ArrayList`s but they would be objects anyway..
Jack
the `ArrayList` itself is a parametrized class that must be attached to a specific type. So the real type of an `ArrayList` includes the type variable: `ArrayList<Employee>` or `ArrayList<String>`
Jack
Thirst for Excellence