package com.sbs.java8.praticse;
import java.util.Arrays;
public class AnagramClass {
public static void main(String[] args) {
String firstString = "1MASS1111124";
String secondString = "1SAMS1111124";
boolean status = false;
if (validateString(firstString,secondString)) {
char array1[] = firstString.toLowerCase().toCharArray();
char array2[] = secondString.toLowerCase().toCharArray();
Arrays.sort(array1);
Arrays.sort(array2);
status = Arrays.equals(array1, array2);
}
System.out.println("Anogram Status " + status);
}
private static boolean validateString(String string,String string2) {
if (string == null || string.isEmpty()) {
return false;
}
if (string2 == null || string2.isEmpty()) {
return false;
}
if(string.length() != string2.length()){
return false;
}
return true;
}
}
import java.util.Arrays;
public class AnagramClass {
public static void main(String[] args) {
String firstString = "1MASS1111124";
String secondString = "1SAMS1111124";
boolean status = false;
if (validateString(firstString,secondString)) {
char array1[] = firstString.toLowerCase().toCharArray();
char array2[] = secondString.toLowerCase().toCharArray();
Arrays.sort(array1);
Arrays.sort(array2);
status = Arrays.equals(array1, array2);
}
System.out.println("Anogram Status " + status);
}
private static boolean validateString(String string,String string2) {
if (string == null || string.isEmpty()) {
return false;
}
if (string2 == null || string2.isEmpty()) {
return false;
}
if(string.length() != string2.length()){
return false;
}
return true;
}
}
Comments
Post a Comment