Coders Packet

Anagram detection using Java

By Khushboo Jagwani

Java program to compare if 2 strings are anagram using sort() and equal() method. Two resembling strings are said to be anagram otherwise not .

 

In this program, we compare 2 strings and check if they are anagram or not.

what is an anagram?

Two words containing the same letters but in jumbled order and all the letters occurring once is called Anagram.

for example: DustY NigHt = stuDY tHiNg

                    arC = Car

Here, in order to change the case of a string, we will change the case of both the strings into a lower case and remove all the white spaces from the string. The input string is converted into a character array and then sorted using the sort() method. equals() method is used to compare the strings after sorting the array of the same array class. The result will be true or positive if the characters are the same and the condition is satisfied otherwise it will return false.

 

Download project

Reviews Report

Submitted by Khushboo Jagwani (Khush123)

Download packets of source code on Coders Packet