Used for each data type conversion - Summary 2 (StringToStringNumber)

{class StringToNumberString public
public static void main (String [] args) {
//. 1. Create a pure string of numbers and characters to be cut consisting
String str = "1,2,3,4,5,5,6,776 , 6767,5 ";
// array 2 because it is operating, so it must use a string method, string class by the method of the split cutting string
string [] = str.split str1 (", ");
//. 3 Since pure string array to an array of integers, so use integer method, i.e. the Integer.parseInt () to convert the string to an integer array
//3.1 defined integer array
int [] arr = new int [ str1. length];
for (int I = 0; I <arr.length; I ++) {
// 3.2 by the process of sequentially assigned integer array
ARR [I] = the Integer.parseInt (str1 [I]);
}
. //. 4 to give after shaping array, since the need to convert it to a string, the use of the method in StringBuilder, eleven strings connected composition of the integer sequence after extraction
//4.1 established StringBuilder object
StringBuilder StringBuilder new new SB = ();
for (int i = 0; i <arr.length; i ++) {
after //4.2 extracted from the digital array by append () method spliced together to form a string
sb.append(arr[i]).append(i==arr.length-1?" “:”,");
}
//5.打印结果
System.out.println(sb);
}
}

Released three original articles · won praise 0 · Views 115

Guess you like

Origin blog.csdn.net/luoyanlin0021/article/details/104733628