List size and empty flag
boolean isEmpty()
- Returns true if this list contains no elements.
int size()
- Returns the number of elements in this list.
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
List list = new ArrayList();
list.add("1");
list.add("2");
list.add("3");
list.add("java2s.com");
System.out.println(list);
System.out.println(list.isEmpty());
System.out.println(list.size());
}
}
The output:
[1, 2, 3, java2s.com]
false
4