List size, empty
In this chapter you will learn:
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;
/* j a va 2 s. c o m*/
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:
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » Collections