7 thoughts on “Check IsAnagram programming In Java

  1. My code

    public boolean isAnagram(String s1, String s2) {

    if(s1.length()!=s2.length()) {
    System.out.println("given string is not anagram…");
    return false;
    }

    for(Character ch: s1.toCharArray()) {
    if(!(s2.indexOf(ch) >=0)) {
    System.out.println("given string is not anagram…");
    return false;
    }
    }
    System.out.println("given string is anagram…");
    return true;
    }

    public static void main(String[] args) {

    IsAnagram IA = new IsAnagram();
    IA.isAnagram("Java", "avaJ");
    }

  2. Their is a catch in a program if length of "String A2" is less than it is displaying it is a anagram For E.G String a1= "Bhanu" and string a2= "nahb".when we run the program its displaying its a anagram.so,sir can you please tell me the approach how we correct this.

  3. hi bhanu i am getting error for this two string s1=""fullybat" and s2="batyllu" i think you should keep stringbuilder object inside for loop.
    like:
    char[] charr = s1.toCharArray();
    StringBuilder s = null;
    for(Character ch: charr)
    {
    s = new StringBuilder(s2);
    int index = s2.indexOf(ch);
    System.out.println("Character of first string "+ch);

    if(index!=-1)
    {
    System.out.println("this got deleted "+s.charAt(index));
    s.deleteCharAt(index);
    System.out.println("string left is : "+s);

    }

    }

  4. I liked your way of teaching..please post more videos what are required for selenium automation…These days getting job in automation became very difficult..please help me how to prepare and what to prepare…thanks for the video…
    this is first time I am posting comment

Leave a Reply

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