Answers for "how to find the size of array list in java"

0

how to get a list length in java

import java.util.ArrayList;
import java.util.List;
public class Demo {
   public static void main(String[] args) {
      List aList = new ArrayList();
      aList.add("Apple");
      aList.add("Mango");
      aList.add("Guava");
      aList.add("Orange");
      aList.add("Peach");
      System.out.println("The size of the ArrayList is: " + aList.size());
   }
}
Posted by: Guest on September-13-2021
0

ArrayList size() method in java

import java.util.ArrayList;
public class ArrayListSizeMethodExample
{
   public static void main(String[] args)
   {
      ArrayList<String> al = new ArrayList<String>();
      int s = al.size();
      System.out.println("size of ArrayList: " + s);
      al.add("red");
      al.add("blue");
      al.add("green");
      s = al.size();
      System.out.println("size of ArrayList after adding elements: " + s);
      al.clear();
      s = al.size();
      System.out.println("size of ArrayList after clearing elements: " + s);
   }
}
Posted by: Guest on October-29-2020

Code answers related to "how to find the size of array list in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language