We can say if two strings are an anagram of each other if they contain the same characters but at different orders.

    

 We can say if two strings are an anagram of each other if they contain the same characters but at different orders.

String str1="sateesh";

String str2="sateehs";


Output: Same 





import java.util.Arrays;


public class Demo1 {

public static void main(String[] args) {


    String str1="sateesh";

    String str2="sateehs";


       


        boolean [] char_set = new boolean[256];

        boolean [] char_set1 = new boolean [256];



        for(int i =0;i<str1.length();i++){


            int val1 = str1.charAt(i);

            int val2 = str2.charAt(i);


            char_set[val1] = true;

            char_set1[val2] = true;

        }


        if(Arrays.equals(char_set, char_set1)){

            System.out.println("Same");

        }

        else

        {

        System.out.println("Not a same");


        }

     


}

}





Output:

same

more programs visit http://sateeshm.com/

No comments:

Post a Comment