ArrayList<String> list = new ArrayList<>();
list.add("cat");
list.add("dog");
list.add("bird");
boolean found = false;
for (String s : list) {
if (s.equals("dog")) found = true;
}
System.out.println(found);What is printed?
- Acheck_circle
true
- B
false
- C
dog
- D
1
Explanation
"dog" is in the list, so the if statement sets found to true.