How to find does ArrayList contains elements or not

we use contains() and  Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ?  e==null : o.equals(e)).

import java.util.ArrayList;

public class ContailsElement {

public static void main(String[] args) {

ArrayList<String> arr = new ArrayList<String>();
// add element in arraylist
arr.add(“c”);
arr.add(“php”);
arr.add(“html”);
arr.add(“java”);
// print arraylist
System.out.println(“arrayList is = ” + arr);
/*
* Returns true if this list contains the specified element
*/
System.out.println(arr.contains(“php”));

System.out.println(arr.contains(“more”));
}

}

Output:

arrayList is = [c, php, html, java]

true

false

Related Posts:


Notice: compact(): Undefined variable: limits in /home/javaprof/public_html/wp-includes/class-wp-comment-query.php on line 853

Notice: compact(): Undefined variable: groupby in /home/javaprof/public_html/wp-includes/class-wp-comment-query.php on line 853

Leave a Reply

Your email address will not be published. Required fields are marked *

59 + = 68