2. How to determine whether 2 strings have the same character composition such as "AAAABBC" and "ABCBAAA"
2 Kinds of ideas
Import Java.lang.reflect.array;import java.util.arrays;//thought one: First sort 2 strings, in comparison, the so-called 2 string equal refers to the number of letters and numbers that make up a string, The order can be different public class Thesamestring {public static void compare (String s1,string s2) {byte[] b1=s1.getbytes (); byte[] B2= S2.getbytes (); Arrays.sort (B1); Arrays.sort (B2); S1=new string (B1); S2=new string (B2); if (s1.equals (s2) ==true) {System.out.println ("equal");} ELSE{SYSTEM.OUT.PRINTLN ("Not Equal");}} public static void Main (string args[]) {string s1= "AAABBBCCC"; String s2= "ABABACBCC"; compare (s1, S2); String s3= "AABBCCDD"; String s4= "abc"; compare (S3, S4);}}
Results: Equalnot Equal
String2 of written interview for Java programmer