标签:题目 java ble order sans data size value enter
今天在群里看到一人说起面试挂的一题,题目是Int数组转成String数组。
尽管是基础的问题。但却是基础中比較少用到的问题,因此大家工作都没怎么遇到,不会也非常正常。在此整理一下,先来个String与Int 互相转换吧
<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>
<span style="font-size:18px;">String st = "11"; int num = Integer.parseInt(st); </span>
<span style="font-size:18px;">String st = "11"; int num = Integer.valueOf(st).intValue();</span>
第一种方法:s=i+"";
第一种方法:i=Integer.parseInt(s);//直接使用静态方法,不会产生多余的对象。但会抛出异常 |
<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>
<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>
标签:题目 java ble order sans data size value enter
原文地址:http://www.cnblogs.com/ljbguanli/p/7067107.html