Wednesday, January 7, 2015

String Annon Check Example




Annon means two words having same characters and same length.
Same characters means both words made of a common set of characters.
i.e teacher and cheater both words have same length and same set of characters, so we can say such types of string or word as Annon String or Annon word.


For more details see below written code to check that two string are Anon or not.
public void testAnnon()
      {
           String str1="teacher";
           String str2="cheater";
 
            char[]ch1=str1.toCharArray();
            char[] ch2=str2.toCharArray();
            Arrays.sort(ch1);
            Arrays.sort(ch2);
           
            boolean  flag=Arrays.equals(ch1, ch2);
            if(flag)
            {
                  System.out.println("Given strings are annon");
            }
            else
            {
                  System.out.println("Given strings are not annon");
            }
      }

No comments:

Post a Comment

Spring Boot Config Server and Config Client.

 In Spring cloud config we can externalise our configuration files to some repository like GIT HUT, Amazon S3 etc. Benefit of externalising ...