如何在Java String中找到给定单词的存在?

时间:2012-09-29 11:35:21

标签: java string

  

请参阅:
  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?

我有两个字符串,如下:

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

我想知道如何在字符串str1中找到“正在”这个词,即使str1如此更改:

str1 = "He isdoing very good";

2 个答案:

答案 0 :(得分:7)

最简单的方法是

str1.contains(str2);

答案 1 :(得分:1)

String.contains方法怎么样?