Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to turn a numeric string into an integer array int[] in java
How to turn a numeric string into an integer array int[] in java
1, define a numeric string.

String? str? =? " 1289898"; 2. Declare an int array according to the length of the string.

int? ia[]? =? New? int[str . length()]; 3. Loop the string and get the string through charAt.

for(int? I = 0; I & ltstr. length (); i++){

Charles? c? =? str . charat(I); //Get the characters in the string one by one.

}4. Subtract the' 0' character from the obtained string C, which is the actual number.

for(int? I = 0; I & ltstr. length (); i++){

Charles? c? =? str . charat(I); //Get the characters in the string one by one.

ia[I]=(int)(c-' 0 '); //Number of Characters-The character 0 is the actual numeric value and is assigned to the numeric array.

}