This section demonstrates the use of contains() method of the ArrayList
This section demonstrates the use of contains() method of the ArrayList
import java.util.ArrayList;
import java.util.List;
public class list_contain {
public static void main(String[] args) {
List list=new ArrayList();
String names[]={"mac","john","alexender","rock","alex"};
for (int i = 0; i < names.length; i++) {
list.add(names[i]);
}
if(list.contains("rock")) {
System.out.println("rock is present in the list ");
}
else {
System.out.println("rock is not present in the list ");
}
}
}
output
rock is present in the list