String s2="6928910608113692910 s8113 60, 69289106 x07390x";
Comparing the strings s1 and s2 above, because the s1 and s2 is the object of a specific value, so want to convert an object of s2 to map, the key for s2 or s2 converted string
How to the fastest will be the two reorder for the same string in the string content
CodePudding user response:
The problem you describe is not clear, reorder the same string not refers to all the characters on average assigned to two strings, or of two characters to get together string string?Here gives the example of the former code (i.e., average distribution characters)
public class Sample {
Public static void main (String [] args) {
String s1="69289106 x07390x, 692891060 s8113, 5420056134897".
String s2="6928910608113692910 s8113 60, 69289106 x07390x";
Char [] c1=s1. ToCharArray ();
Char [] c2=s2. ToCharArray ();
The Arrays. ParallelSort (c1);//two string collation
The Arrays. ParallelSort (c2);
System. The out. Println (new String (c1));//sort the results
System. The out. Println (new String (c2));
The StringBuilder sb1=new StringBuilder ();
The StringBuilder sb2=new StringBuilder ();
Int I=0, j=0;
For (; iIf (c1==c2 [j] [I]) {//if the same
Sb1. Append (c1 [i++]);//each take the characters
Sb2. Append (c2 [j++]);
} else if (c1 [I] & gt; C2 [j]) {//if c1
If (j + 1 & lt; C2. Length& & C2 [j]==c2 [m + 1]) {//if the c2 continuous two same
Sb1. Append (c2 [j++]);//is distributing the c2 to c1
Sb2. Append (c2 [j++]);
} else {//or abandon the c2 (because no double, evenly)
j++;
}
} else {//if the c2 big
If (I + 1 & lt; C1. Length & amp; & C1 [I]==c1 [I + 1]) {//if c1 continuous two same
Sb1. Append (c1 [i++]);//is distributing the c1 to c2
Sb2. Append (c1 [i++]);
} else {//or abandon c1 (because no double, evenly)
i++;
}
}
}
for(; iIf (I + 1 & lt; C1. Length & amp; & C1 [I]==c1 [I + 1]) {
Sb1. Append (c1 [i++]);
Sb2. Append (c1 [i++]);
} else {
i++;
}
}
For (; jIf (j + 1 & lt; C2. Length & amp; & [j]==c2 c1 [m + 1]) {
Sb1. Append (c2 [j++]);
Sb2. Append (c2 [j++]);
} else {
j++;
}
}
System. The out. Println (sb1. ToString ());//s1 eventually restructuring the results
System. The out. Println (sb2. ToString ());//s2 eventually restructuring results (same as s1)
}
}