ArrayListClearEmptySizeExample.java
import java.util.ArrayList; /* * Example of isEmpty(),clear() and size() methods */ public class ArrayListClearEmptySizeExample { public static void main(String[] args) { ArrayList<String> arrayList = new ArrayList<String>(); arrayList.add("Ram"); arrayList.add("Dave"); arrayList.add("Peter"); arrayList.add("Julia"); arrayList.add("Akram"); System.out.println("arrayList : " + arrayList ); int size; boolean isEmpty; size = arrayList.size(); System.out.println("size : " + size); isEmpty = arrayList.isEmpty(); System.out.println("isEmpty : " + isEmpty); arrayList.clear(); System.out.println("\nAfter list is cleared :" + arrayList ); size = arrayList.size(); System.out.println("size : " + size); isEmpty = arrayList.isEmpty(); System.out.println("isEmpty : " + isEmpty); } }
arrayList : [Ram, Dave, Peter, Julia, Akram] size : 5 isEmpty : false After list is cleared :[] size : 0 isEmpty : true
https://sites.google.com/site/javaee4321/java-collections/ArrayListDemoClearEmptysize.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment