0

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
Edax
  • 37
  • 1
  • 2
  • 7
  • 3
    `contains()` should be what you are looking for. – Alexis C. May 03 '14 at 18:53
  • possible duplicate of [In Java, how can I test if an Array contains a certain value?](http://stackoverflow.com/questions/1128723/in-java-how-can-i-test-if-an-array-contains-a-certain-value) – user3591723 May 03 '14 at 18:56
  • 1
    The Python the `in` operator maps to the object's `__contains__()` method. I believe Java string objects have something similar. – martineau May 03 '14 at 18:57

2 Answers2

6

For strings there is:

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

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

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
2

Nope. You should do

"jimbo".contains("jim")
perencia
  • 1,498
  • 3
  • 11
  • 19