ArrayList.size()

ArrayList

ArrayList.size() Number of elements present inside the ArrayList.


Examples with output

add()
We will use size() to get the total number of elements present inside the ArrayList.
ArrayList<Integer> marks = new ArrayList<Integer>();
marks.add(55);
marks.add(54);
marks.add(55);
marks.add(54);
System.out.println(marks.size()); //4
Looping through ArrayList
ArrayList<Integer> marks = new ArrayList<Integer>(3);
marks.add(55);
marks.add(54);
marks.add(60);
for(int i=0; i < marks.size(); i++)
	System.out.println(marks.get(i)); 
Output
55
54
60
We used one for loop and get() to collect each element inside the ArrayList.
Example using string
ArrayList<String> languages = new ArrayList<String>();
languages.add("Java");
languages.add("PHP");
languages.add("Python");
for(int i=0;i<languages.size();i++)
System.out.println(languages.get(i));
Output
Java
PHP
Python
ArrayList Tutorials



plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer