I want to know if there's a way of doing something like this in Java :
if(word in stringArray) { ... } I know I can make a function for this but I just want to know if Java has already something for this.
Thank you!
The SQL IN Operator The IN operator allows you to specify multiple values in a WHERE clause. The IN operator is a shorthand for multiple OR conditions.
The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two wildcards often used in conjunction with the LIKE operator: The percent sign (%) represents zero, one, or multiple characters.
There are many collections that will let you do something similar to that. For example:
With Strings:
String s = "I can has cheezeburger?"; boolean hasCheese = s.contains("cheeze"); or with Collections:
List<String> listOfStrings = new ArrayList<String>(); boolean hasString = listOfStrings.contains(something); However, there is no similar construct for a simple String[].
In SQL
x in ('Alice', 'Bob', 'Carol') In Java:
Arrays.asList("Alice", "Bob", "Carol").contains(x)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With