Substring search in Java

前端 未结 6 402

I have a problem with string comparison. For example, there is this string:

\"hello world i am from heaven\"

I want to search if this strin

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-18 07:19

    For an exact String comparison, you can simply do:

    boolean match = stringA.equals(stringB);
    

    If you want to check that a string contains a substring, you can do:

    boolean contains = string.contains(substring);
    

    For more String methods, see the javadocs

提交回复
热议问题