A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Java program to search an element from an ArrayList
Q:

Java program to search an element from an ArrayList

0

Given an ArrayList, and we have to find/search an element from the list using Java program.

ArrayList.contains()

Method is used to check whether an element is exists in the ArrayList or not, this method return "false" if element is not found, and returns "true" if element exists in the ArrayList.

Syntax:

boolean ArrayList.contains(element);

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the program

import java.util.ArrayList;

public class SearchAnElement {

  public static void main(String[] args) {
    //ArrayList object 
    ArrayList arrList = new ArrayList();

    //adding elements in the list
    arrList.add("100");
    arrList.add("200");
    arrList.add("300");
    arrList.add("400");
    arrList.add("500");

    //searching element "300"
    boolean isFound = arrList.contains("300");
    if (isFound == false)
      System.out.println("Element is not found in the list");
    else
      System.out.println("Element is found in the list");

  }
}

Output

Element is found in the list

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now