I'm teaching myself how to code with java and I use exercises I find in the Internet to practice what I learn.
I am now in a middle of a question that asks me to compare between two strings(input from the user) and check if the two contain the same letters.
example:
areAnagrams("asd","dsa") -> true
areAnagrams("Debit Card","Bad Credit")=> true
got the idea?
I know that the == check only if them both are refering to the same object. I thought that
public int compareTo(String otherString)
should have done the job. but it doesnt work =\
what i did till now is:
public static boolean areAnagrams(String a, String b)
{
int x=0;
a.trim();
b.trim();
x=a.compareTo(b);
System.out.println(x);
return x==0 ? true:false;
}
public static void main(String[] args)
{
Scanner temp= new Scanner(System.in);
Scanner temp2= new Scanner(System.in);
String a= temp.next();
String b= temp2.next();
System.out.println(areAnagrams(a,b));
}
}
but it doesnt work. i think there is a command that should compare value's but i couldnt find it online.
will apriciate your help
thanks!