user3425204
user3425204

Reputation: 1

Size of ArrayList

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

Answers (4)

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

arshajii
arshajii

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

Salah
Salah

Reputation: 8657

To determine the list size use:

shares.size();

To determine a specific size use:

shares.get(index).size();

Upvotes: 0

user1907906
user1907906

Reputation:

int List.size() does exist. Use it.

int rows = shares.size();
for (List<Byte> row : shares) {
    int columns = row.size();
}

Upvotes: 1

Related Questions