one is a permutation of theother

Run Settings
LanguageJava
Language Version
Run Command
//Given two strings,write a method to decide if one is a permutation of the other. import java.util.Arrays; import java.util.Scanner; class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); String a = s.nextLine(); String b = s.nextLine(); Main m = new Main(); System.out.println(m.isPermutation(a,b)); } public boolean isPermutation(String a, String b){ if(a == null || b == null){ return false; } if(a.length() != b.length()){ return false; } return sort(a).equals(sort(b)); } private String sort(String a){ char[] b = a.toCharArray(); Arrays.sort(b); return new String(b); } }
Editor Settings
Theme
Key bindings
Full width
Lines