Friday, 10 October 2014

Java : Collection Framework : ArrayList (Clear|Empty|Size)
























Click here to watch in Youtube : https://www.youtube.com/watch?v=aD_3_pS-6ao

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);

    }

}

Output
arrayList : [Ram, Dave, Peter, Julia, Akram]
size : 5
isEmpty : false

After list is cleared :[]
size : 0
isEmpty : true

To Download ArrayListDemoClearEmptysize Project Click the below link

https://sites.google.com/site/javaee4321/java-collections/ArrayListDemoClearEmptysize.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • No comments:

    Post a Comment