1.

What is the difference between length() and size() of ArrayList?(a) length() and size() return the same value(b) length() is not defined in ArrayList(c) size() is not defined in ArrayList(d) length() returns the capacity of ArrayList and size() returns the actual number of elements stored in the listThe question was posed to me in an interview.The query is from Data Structures-List in section java.util – The Collections Framework of Java

Answer»

Correct answer is (d) length() returns the capacity of ArrayList and size() returns the actual NUMBER of elements stored in the LIST

Explanation: length() returns the capacity of ArrayList and size() returns the actual number of elements stored in the list which is ALWAYS less than or EQUAL to capacity.



Discussion

No Comment Found

Related InterviewSolutions