I have four arrays of strings and I would like to create a two dimensional array of 3 columns and dynamic rows.
the arrays are like:
String[] first_name;
String[] last_name;
String[] unit;
String[] phone_number;
Object[][] obj = new Object[first_name.length()][3]
My problem is how do I achieve something like this:
obj = {first_name[index] + " " + last_name[index], unit[index], phone_number[index]}
Please help out!!!
I am assuming that by dynamic rows you mean that it depends on the number of elements in the
first_namearray.So you could simply iterate:
However, this approach is not very good. You should consider creating an object for example named
Employeewhich as the 3 fields, and then you just have an array ofEmployeeFor example:
And then you just have: