Answers for "list length java"

2

get number of items in arraylist java

import java.util.ArrayList;

/*
 * Java Program to find the length of ArrayList. *
 */

public class ArrayListDemo{

  public static void main(String[] args) {
    System.out.println("Welcome to Java Program to find the length of array list");

    ArrayList<String> listOfBanks = new ArrayList<>();
    int size = listOfBanks.size();
    System.out.println("size of array list after creating: " + size);

    listOfBanks.add("Citibank");
    listOfBanks.add("Chase");
    listOfBanks.add("Bank of America");
    size = listOfBanks.size();

    System.out.println("length of ArrayList after adding elements: " + size);

    listOfBanks.clear();
    size = listOfBanks.size();
    System.out.println("size of ArrayList after clearing elements: " + size);
  }

}
Output
Welcome to Java Program to find length of array list
the size of array list after creating: 0
the length of ArrayList after adding elements: 3
the length of ArrayList after clearing elements: 0
Posted by: Guest on April-16-2020
2

list size in java

Collection<Object> list = new ArrayList<>();
        list.size();
        
        // All collections use size()
        // array use array. length
Posted by: Guest on April-12-2021
1

size list java

Before operation: [1, 2, 3, 4, 5]
Size of list = 5
Posted by: Guest on May-22-2021
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

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language