Java Program to Search an Element From an ArrayList

You are currently viewing Java Program to Search an Element From an ArrayList

Java program to search an element from an ArrayList

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

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply