Avatar ·

How to check if an array contains a specific value in Java?

Hello everyone! I'm just starting to learn Java and came across a task that seems simple, but I can't find an elegant solution. I have a string array with usernames: ```java String[] users = {"Alice", "Bob", "Charlie", "Diana"}; ``` I need to check if the name "Charlie" is in this array. Currently I'm doing it with a `for` loop: ```java boolean found = false; for (int i = 0; i < users.length; i++) { if (users[i].equals("Charlie")) { found = true; break; } } if (found) { System.out.println("User found!"); } ``` This works, but the code looks cumbersome. I know that in Python you can write `if "Charlie" in users:`, and it's one line. Is there something similar in Java? Maybe there's a built-in method or library?