728x90
반응형
import java.util.Arrays;
String[] fruits = {"Apple", "Banana", "Cherry"};
String target = "Banana";
boolean found = Arrays.asList(fruits).contains(target);
if (found) {
System.out.println(target + " is in the array.");
} else {
System.out.println(target + " is not in the array.");
}
728x90
반응형
'JAVA' 카테고리의 다른 글
[JAVA] LocalDate minusDays (0) | 2024.09.01 |
---|---|
[JAVA] for문에서 return false/ continue (0) | 2024.08.31 |
[JAVA] Stream API anyMatch() (0) | 2024.08.20 |
[JAVA] Arrays.asList (0) | 2024.08.19 |
[JAVA] DateTimeFormatter (0) | 2024.06.22 |