Is the size() method the ArrayList class simply a getter, or does it perform any sort of calculation?
If it is a getter then is it safe to assume that it will be inlined at some point if I call it a large number of times?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you’re asking if there’s any overhead in calling “size()”, the answer is “No”.
Here’s a similar discussion on a similar method, String.length():
In Java, for a string x, what is the runtime cost of s.length()? Is it O(1) or O(n)?
The answer in both cases – String.length() and ArrayList.size() – is “O(1)”.