How to check if a specific name is in my array list
i must return true if it is and false if it isnt
// Answer is use the method contains //contains() return true if element is in ArrayList //else returns False import java.util.ArrayList; public class MyArrayList { public static void main(String[] args) { ArrayList<String> arr = new ArrayList<String>(4); arr.add("Ram"); arr.add("Krishna"); arr.add("Jon"); arr.add("Don"); //test the method System.out.println("Ram in array list? "+arr.contains("Ram")); System.out.println("Jennie in array list? "+arr.contains("Jennie")); } }
Get Answers For Free
Most questions answered within 1 hours.