Tristan
Tristan

Reputation: 31

Using size of an array list

When I calling the size method of my ArrayList, I get the error:

size has private access in ArrayList.

Any advice on this?

ArrayList<String> sAnswers = new ArrayList<>();
int arrayL = sAnswers.size;

Upvotes: 0

Views: 1617

Answers (2)

Amit.rk3
Amit.rk3

Reputation: 2417

There is no accessible size variable in List. It's a method

Access it like sAnswers.size();

Upvotes: 4

Qbert
Qbert

Reputation: 102

size is a private variable in List. Use someList.size().
length is a public variable in an Array. Use someArray.length.

ArrayList<String> sAnswers = new ArrayList<>();
int arrayL = sAnswers.size();

Upvotes: 2

Related Questions