java.lang.StringIndexOutOfBoundsException: String index out of range

后端 未结 3 1890
别跟我提以往
别跟我提以往 2021-01-06 16:56

Hi I wrote a java code to find longest word made of other words. My logic is to read the list of words from the text file and add each word into an array (In the text the wo

3条回答
  •  生来不讨喜
    2021-01-06 17:39

    A few tips:

    First, always include the full stack trace when you are asking for debugging help. It should point to the exact line number the issue is happening on.

    Second, your issue is likely in your most inner loop for(int j1=0;j1 you are incrementing i1 in addition to j1 this will cause i1 to eventually go beyond the size of String s

    Finally, you should consider using the String.contains() method for Strings or even a Regular Expression.

提交回复
热议问题