Today in the group to see a person talking about the interview hangs a question, the topic is an int array to string array. Although it is the basic problem, but it is less used in the basis of the problem, so everyone work is not how to meet, not also very normal. Here, let's start with a string and int convert each other.
int to string (for example, two types)
<span style= "FONT-SIZE:18PX;" >int num = 2; String st = "" + num;</span>
<span style= "FONT-SIZE:18PX;" >int num = 2; String st = string.valueof (num) </span>
string to int (for example, two types)
<span style= "FONT-SIZE:18PX;" >string st = "one"; int num = integer.parseint (ST);</span>
<span style= "FONT-SIZE:18PX;" >string st = "one"; int num = integer.valueof (ST). Intvalue ();</span>
There are two ways to convert, so what good is it?
First method: s=i+ ""; //produces two string objects second method: s= String.valueof (i); Use the static method of the string class directly, producing only one object The first method: I=integer.parseint (s);//Use static methods directly, do not produce extra objects, but throw exceptions the second method: i= Integer.valueof (s). Intvalue ()//integer.valueof (s) equals the new Integer (Integer.parseint (s)) and throws an exception, but produces an object more |
int array turns into a string array
<span style= "FONT-SIZE:18PX;" >int [] num = new int[1,2,3,4,5]; String [] st = new String[num.length]; <span style= "White-space:pre" ></span> for (int i=0; i<num.length;i++) { <span style= " White-space:pre "></span>st[i] = num[i]. ToString ();} </span>
convert string array to int array
<span style= "FONT-SIZE:18PX;" >string [] st= new string["1", "2", "3", "4", "5"];int[] num = new Int[st.length]; <span></span> for (int i=0; i<st.length;i++) { <span></span>num[i] = Integer.parseint (St[i])}</span>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
int arrays and string arrays convert each other and function to each other