0

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;

2 Answers 2

4

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

Access it like sAnswers.size();

Sign up to request clarification or add additional context in comments.

Comments

2

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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.