xxxxxxxxxx
import java.util.List;
public class ListLengthExample {
public static void main(String[] args) {
List<String> myList = List.of("apple", "banana", "orange");
int length = myList.size();
System.out.println("Length of the list: " + length);
}
}
xxxxxxxxxx
ArrayList<String> listOfBanks = new ArrayList<>();
int size = listOfBanks.size();
System.out.println("size of array list after creating: " + size);
xxxxxxxxxx
import java.util.List;
public class Main {
public static void main(String[] args) {
List<String> myList = List.of("apple", "banana", "orange");
int length = myList.size();
System.out.println("The length of the list is: " + length);
}
}
xxxxxxxxxx
List<?> list = new ArrayList<>(); // Replace '?' with the type of objects stored in the list
int length = list.size();
System.out.println(length); // This line is optional, used to display the length