Shamoon Shamoon - 3 months ago 10
Java Question

How can I iterate over a string in Java?

public static Boolean cmprStr( String s1, String s2 )
{
// STUFF
}


I want to iterate through s1 to make sure that every character in s1 is included in s2.

Answer
public static Boolean cmprStr( String s1, String s2 )
{
    for (int i = s1.length() - 1; i >= 0; --i) {
         if (s2.indexOf(s1.charAt(i)) == -1) {
             return Boolean.FALSE;
         }
    }
    return Boolean.TRUE;
}