This is my code below to check anagram of a given string array.
It always gives me false even in the simplest case with only one input.
I don't understand am I not converting string array into string correctly or my algorithm is plain wrong.
public class anagram
{
static boolean isAnagram(String[] s1, String[] s2) {
String str = s1.toString();
String str2 = s2.toString();
if (str.length() != str2.length())
return false;
for (int i =0; i<str.length();i++)
{
for (int j = 0;j<str2.length();j++)
{
if (s1[i] == s2[j]) {
return true;
}
return false;
}
}
return true;
}
public static void main(String [] args){
String [] s1 = {"shot"};
String [] s2 = {"host"};
System.out.println(isAnagram(s1,s2));
}
}
Can you please help me identify what is wrong?