in Technology by
What is the difference between the length of an Array and size of ArrayList in Java?

1 Answer

0 votes
by

The length of an array can be obtained using the property of length whereas ArrayList does not support length property, but we can use size() method to get the number of objects in the list.

Finding the length of the array

  1. Int [] array = new int[4];  
  2. System.out.println("The size of the array is " + array.length);  
  3.           

Finding the size of the ArrayList

  1. ArrayList<String> list=new ArrayList<String>();    
  2. list.add("ankit");    
  3. list.add("nippun");  
  4. System.out.println(list.size());  
  5.           

Related questions

0 votes
    What is the difference between length() and size() of ArrayList? (a) length() and size() return the ... Collections Framework of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    What is the difference between length() and size() of ArrayList? (a) length() and size() return ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    What is the difference between Array and ArrayList in JAVA?...
asked May 27, 2021 by JackTerrance
0 votes
    How to convert ArrayList to Array and Array to ArrayList in JAVA?...
asked May 27, 2021 in Technology by JackTerrance
0 votes
    Which of these methods can be used to obtain a static array from an ArrayList object? (a) Array() ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    What is the difference between ArrayList and LinkedList?...
asked May 26, 2021 in Technology by JackTerrance
0 votes
    What is the difference between ArrayList and Vector?...
asked May 26, 2021 in Technology by JackTerrance
0 votes
    Which of these method of ArrayList class is used to obtain present size of an object? (a) size() ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    What is the difference between pointer to an array and array of pointers?...
asked Jan 22, 2021 in Technology by JackTerrance
0 votes
    I am writing a program to optimize a transportation system. I have an ArrayList "passengers" of 65,000 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I am writing a program to optimize a transportation system. I have an ArrayList "passengers" of 65,000 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 10, 2022 in Education by JackTerrance
0 votes
    Which of these class can generate an array which can increase and decrease in size automatically? (a) ... questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
...