Friday 10 October 2014

Java : Collection Framework : ArrayList (Check Object Exist or not)
























Click here to watch in Youtube : https://www.youtube.com/watch?v=5V62NktM51Y

ArrayListContainsExample.java
import java.util.ArrayList;

/*
 * Example of contains(Object o) method
 */
public class ArrayListContainsExample
{

    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 + "\n");

        boolean isExist;

        isExist = arrayList.contains("Ram");

        System.out.println("Is 'Ram' exist :  " + isExist);

        isExist = arrayList.contains("Karthick");

        System.out.println("Is 'Karthick' exist :  " + isExist);

    }

}


Output
ArrayList : [Ram, Dave, Peter, Julia, Akram]

Is 'Ram' exist :  true
Is 'Karthick' exist :  false


To Download ArrayListDemoContainsProject Click the below link

https://sites.google.com/site/javaee4321/java-collections/ArrayListDemoContains.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