Skip to content Skip to sidebar Skip to footer

Does Java Have An "in" Or "not In" Operator Similar To Python?

I'm working on a project in Java and I wanted to know if Java had a similar 'in'/'not in' operator in Python like the example below. >>>'jim' in 'jimbo' >>>True

Solution 1:

For strings there is:

"jimbo".contains("jim"); //true

Check the documentation for String. There is also startsWith, endsWith and matches (which uses regular expressions).

Solution 2:

Nope. You should do

"jimbo".contains("jim")

Post a Comment for "Does Java Have An "in" Or "not In" Operator Similar To Python?"