[Solved] Operations on Strings


If two strings are equal to each other.

When comparing two strings, you have to pass in the strings.

public static boolean isEquals(String a, String b) {
   if (a.length() != b.length()) return false;
   return isEquals(a, b, 0);
}

private static boolean isEquals(String a, String b, int index) {
    if (index >= a.length()) return true;
    if (a.charAt(index) != b.charAt(index)) return false;
    return isEquals(a, b, index + 1);
}

or if performance doesn’t matter

public static boolean isEquals(String a, String b) {
   if (a.length() == 0)
       return b.length() == 0;
   if (b.length() == 0)
       return false;
   return a.charAt(0) == b.charAt(0) &&
       isEquals(a.subString(1), b.subString(1));
}

1

solved Operations on Strings