-5

Please see also:
How to see if a substring exists inside another string in Java 1.4
Searching for one string in another string
How to search a string in another string?

I have two strings, like so:

String str1 = "He is doing very good";
String str2 = "doing";

I want to know how to find the word "doing" in string str1, even if str1 is changed like so:

str1 = "He isdoing very good";
Community
  • 1
  • 1
Sudipta Kumar
  • 39
  • 1
  • 1
  • 5
  • 4
    Check the docs before asking a question. This is as basic as it gets. – keyser Sep 29 '12 at 11:43
  • Check the docs or Google... https://www.google.com/search?q=how+to+find+string+in+another+string+in+java&oq=how+to+find+string+in+another+string+in+java – Buggabill Sep 29 '12 at 12:00
  • Or even just search the previous SO questions. I found this one: http://stackoverflow.com/questions/2940114/searching-for-one-string-in-another-string and many more. – Stephen C Sep 29 '12 at 12:05

2 Answers2

7

The easiest way would be

str1.contains(str2);
Johan Sjöberg
  • 47,929
  • 21
  • 130
  • 148
1

How about the String.contains method?

Michael Ratanapintha
  • 39,422
  • 4
  • 33
  • 40
Matten
  • 17,365
  • 2
  • 42
  • 64