How can I iterate over a string in Java?

前端 未结 9 1753
余生分开走
余生分开走 2021-01-02 12:40
public static Boolean cmprStr( String s1, String s2 )
{
    // STUFF
}

I want to iterate through s1 to make sure that every character in s1 is incl

9条回答
  •  情歌与酒
    2021-01-02 13:15

    length()
    

    will give you the length of a string

    charAt( someIndex)
    

    will give you the character at a given position, so you can iterate the first String.

    indexOf( achar )
    

    will give you the poisition a char in a String, or -1 if it's not there. hence you should be able to look for each character in the first string within the second.

提交回复
热议问题