I would like to create a 2D array named employees where I know the number of columns (fixed 5 and represent employee's data) but number of rows is somewhat dynamic. So I did something like this:
static ArrayList<String[]> employees = new ArrayList<String[]>();
I figured how to add employees but I can't figure out how to get a specific data out of one employee only, using .get() for example.
get would return a row, which is a String[]. If you want a specific value from it, you'll have to subscript it using the [] operator:
String specificData = employees.get(1)[2]; // Or any other indexes
the first dimension which is any ArrayList you have to call by get() method to access and then the returned value is an array which you cann access by index:
ArrayList<String[]> employees = new ArrayList<String[]>();
employees.add(new String[] {"a", "b"});
System.out.println(employees.get(0)[0]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With