Java: Check if two given strings are anagrams or not
Check Anagrams
Write a Java program to check if two strings are anagrams or not.
According to wikipedia "An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. For example, the word anagram can be rearranged into nag a ram, or the word binary into brainy."
Pictorial Presentation:
Sample Solution:
Java Code:
Sample Output:
String-1 : wxyz String-2 : zyxw Check if two given strings are anagrams or not?: true
Flowchart:
For more Practice: Solve these Related Problems:
- Write a Java program to check if two given strings are anagrams while considering case sensitivity.
- Write a Java program to find all the anagrams of a given word in a list of words.
- Write a Java program to check if two given strings are k-anagrams, meaning they can be converted into anagrams by changing at most k characters.
- Write a Java program to check if one string is a cyclic anagram of another (rotation of an anagram).
Java Code Editor:
Previous: Write a Java program to check if a given string has all unique characters.
Next: Write a Java program to merge two given sorted lists.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.