This program demonstrates how to check if an element is present in an ArrayList. The ArrayList is created and initialized with 10 Integer elements from 10 to 100, with an increment of 10. The contains method of ArrayList is used to check if the given elements 30 and 73 are present in the list.
num.contains(30) returns true as 30 is present in the list, whereas num.contains(73) returns false as 73 is not present in the list. Finally, the program prints the boolean result of the contains method for both elements to the console using System.out.println.
import java.util.ArrayList; public class CheckElement_Present { public static void main(String[] args) { ArrayList<Integer> num = new ArrayList<Integer>(); num.add(10); num.add(20); num.add(30); num.add(40); num.add(50); num.add(60); num.add(70); num.add(80); num.add(90); num.add(100); System.out.println("30 is Present in ArrayList ? "+num.contains(30)); System.out.println("73 is Present in ArrayList ? "+num.contains(73)); } }
30 is Present in ArrayList ? true 73 is Present in ArrayList ? false
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions