How to know if a given string is substring from another string in Java

后端 未结 16 1779
情歌与酒
情歌与酒 2020-12-20 18:58

Hi I have to compute if a given string is substring of a bigger string. For example

String str = \"Hallo my world\";
String substr = \"my\"
<
16条回答
  •  猫巷女王i
    2020-12-20 19:26

    public static boolean isSubstring(String s1, String s2){
        if(s1.length()

    This checks if s2 is a substring of s1.

提交回复
热议问题