Can anyone help me? I am trying to compare 2 strings if its equal or not (without considering spaces and cases)
Examples:
"Abc1", "Abc1 " -> true (with spacing at the end)
"Abc1", "abc1" -> true (with lowercase)
"Abc1", " Abc1 " -> true (with spacing at the beginning and at the end of the string)
"Abc1", " abc1 " -> true (with lowercase and spacing at the beginning and at the end of the string)
It should have the same order, and if its not the same order, it will returns false
"Abc1", "Ac1b " -> false
I already tried this code, but it didnt give me the result I was looking for
public static boolean sameChars(String firstStr, String secondStr) {
char[] first = firstStr.toCharArray();
char[] second = secondStr.toCharArray();
Arrays.sort(first);
Arrays.sort(second);
return Arrays.equals(first, second);
}