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
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;
}
Every String
is also a CharSequence
in Java. Therefore, you can easily iterate over a String
using a simple for loop:
int n = s.length();
for (int i = 0; i < n; ++i) {
char c = s.charAt(i);
...
}
Why don't you simply use 'equals' method ?
Boolean b = s1.equals(s2);