I had a big discussion on this issue in many forums just now, so I tried to practice it.
[Problem description]
Determine whether the two strings contain identical characters. For example, "sabac" and "basca" contain exactly the same characters, and the numbers of the same characters must be the same, but their order can be different.
[Problem Analysis]
1. first determine whether the two strings are of the same length
2. Check whether the numbers of characters in a string of the same length are the same.
3. When judging characters, first cut the string into a string array, then sort the character data, and then compare the characters corresponding to the two strings.
[Code implementation]
Public boolean isIncludeSameChar (String str1, String str2) {boolean flag = true; if (str1.length ()! = Str2.length () {flag = false;} else {char [] str1Arr = str1.toCharArray (); Arrays. sort (str1Arr); char [] str2Arr = str2.toCharArray (); Arrays. sort (str2Arr); for (int I = 0; I <str2Arr. length; I ++) {if (str2Arr [I] = str1Arr [I]) {continue;} else {flag = false ;}} return flag ;}
True is returned, otherwise false is returned;