Just on the Internet, see this problem in many forums to get a lot of discussion, so try to practice a bit.
"Problem description"
For two strings, determines whether the included characters are exactly the same. For example, "Sabac" and "Basca" contain exactly the same characters, and the same number of characters is the same, but they can be different in order.
"Problem Analysis"
1. Determine if the length of the two strings is the same
2. Determine whether the characters in a string of the same length and the same number of characters are the same.
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/
3. When judging characters, the string is cut into an array of strings, then the character data is sorted, and then the corresponding characters of two strings are compared.
"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;
}
Returns True the same, otherwise returns false;