ArrayList - isEmpty, size and clear methods program.
import java.util.ArrayList;
import java.util.List;
/**
* Copyright (c), AnkitMittal JavaMadeSoEasy.com
*/
public class ArrayListTest {
public static void main(String args[]) {
// creates array with initial capacity of 10.
List<String> arrayList = new ArrayList<String>();
System.out.println("--------add element to end of list");
arrayList.add("ankit");
arrayList.add("mittal");
arrayList.add("javaMadeSoEasy");
System.out.println("arrayList = "+arrayList);
System.out.println("arrayList.isEmpty() = "+arrayList.isEmpty());
System.out.println("\n--------clear list - remove all elements from list");
arrayList.clear();
System.out.println("arrayList.isEmpty() = "+arrayList.isEmpty());
System.out.println("arrayList = "+arrayList);
}
}
/*OUTPUT
--------add element to end of list
arrayList = [ankit, mittal, javaMadeSoEasy]
arrayList.isEmpty() = false
--------clear list - remove all elements from list
arrayList.isEmpty() = true
arrayList = []
*/
|
RELATED LINKS>