You need to consider:
(1) integer overflow, such as the Numbers for: "99999999999999999999999999999999", cannot be compared to firing a string into an integer;
(2) the first is 0 digital string processing, such as "00000000000000006" is less than the "7",
Written in Java sort algorithm implementation and output after sort of string,
How to put the string of Numbers and letters, respectively in the two arrays, and sort out where they are the same ah
CodePudding user response:
Public static void main (String [] args) {
String STR="aaa77xxxx88jj44kk003";
StringBuilder sb=new StringBuilder();
The StringBuilder sbNum=new StringBuilder ();
ListList=new ArrayList<> (a);
For (char ch1: STR. ToCharArray ()) {
if (! IsNum (ch1)) {
If (sbNum. Length () & gt; 0 {
Sb. Append (" % s ");
List. The add (sbNum. ToString ());
SbNum. SetLength (0);
}
Sb. Append (ch1);
continue;
}
SbNum. Append (ch1);
}
If (sbNum. Length () & gt; 0 {
List. The add (sbNum. ToString ());
Sb. Append (" % s ");
SbNum. SetLength (0);
}
MapThe map=new TreeMap<> (a);
Int start=0;
For (String str1: list) {
Start=0;
For (char ch: str1. ToCharArray ()) {
If (ch=='0') {
start++;
continue;
}
break;
}
The map. The put (str1. Substring (start), null);
}
System. The out. Println (sb. ToString ());
String format=the String. Format (sb. ToString (), new ArrayList<> (map) keySet ()). ToArray ());
System. The out. Println (format);
}
The static Boolean isNum (char ch) {
Return ch>='0' & amp; & Ch<='9';
}
Results;
aaa3xxxx44jj77kk88