Reputation: 1
I am having an arrayList of arraylist Like this
public static ArrayList<ArrayList<Byte> > shares = new ArrayList<ArrayList<Byte> >();
I want to find number of rows in this ArrayList and Number of columns in each of row list also.How to do it.
Please help.
Upvotes: 0
Views: 1199
Reputation: 496
This is shares.size()
=> the number list in the list shares
for(int i = 0;i<shares.size();++i){
shares.get(i).size();// the size of each arraylist in the list shares
}
Upvotes: 0
Reputation: 129572
Each ArrayList<Byte>
in shares
represents a row. So the total number of rows is shares.size()
, and number of columns in row i
is equal to the length of the ArrayList<Byte>
at position i
, which is shares.get(i).size()
.
Upvotes: 0
Reputation: 8657
To determine the list size use:
shares.size();
To determine a specific size use:
shares.get(index).size();
Upvotes: 0
Reputation:
int List.size()
does exist. Use it.
int rows = shares.size();
for (List<Byte> row : shares) {
int columns = row.size();
}
Upvotes: 1