Anagram program in java

Write a java program to find if two Strings are anagram.

This is one of the most popular interview questions asked in companies like Paypal.

What is an Anagram?

Two Strings are said to be anagrams if they contain same number of characters (excluding space), same set of characters but in different order. Following are some of the anagrams.
• dose – does
• used – dues
• care – race
• silent – listen

Anagram finder in Java using HashMap:


silent and LISTEN are anagrams.
Madam Curie and Radium came are anagrams.
Care and Race are anagrams.
Doll and Door are not anagrams.
Does and Dose are anagrams.

It can also be solved in some other ways like using Arrays.sort() method too.

The following two tabs change content below.
Working as a Java developer since 2010. Passionate about programming in Java. I am a part time blogger.
One comment

Add Comment

Required fields are marked *. Your email address will not be published.