If you really want to use a 2-dimensional array, you must first determine the size of the array (also if it is an n-dimensional array!)
See this content for an explanation:
http://www.leepoint.net/notes-java/data/arrays/arrays-2D.html
It seems to me that you have only one size parameter for the array, so I would use a regular array instead of 2-dimensional.
I would do something like this:
public Object[] getData() { customers = dataManager.getUserData(); int size = customers.size(); Object[] result = new Object[size]; Customer customer; for(int i = 0; i < size; i++) { customer = customers.getCustomerAt(i); result[i] = { { Integer.toString(customer.getCustomerID()), customer.getfName(), customer.getlName() } }; } return data; }
If you need to use a 2-dimensional array of objects, you need to determine the size of the second size and fill the array as follows:
for(int i = 0; i < sizeDimOne; i++) { for(int k = 0; k < sizeDimTwo; k++) { result[i][k] = { { Integer.toString(customer.getCustomerID()), customer.getfName(), customer.getlName() } }; } }
Hope this will be helpful.
source share