将ArrayList转化为数组array

方法1 public static String[] readConfig(String inputStr){ StringTokenizer stk = new StringTokenizer(inputStr, ","); ArrayList list = new ArrayList(); int lineNum = 0; while(stk.hasMoreTokens()){ String s = stk.nextToken(); list.add(s); lineNum ++; } String[] returnStr = new String[lineNum] ; for(int i=0;i<lineNum;i++){ returnStr[i] = (String)list.get(i); } return returnStr; 方法2 public static String[] readConfig(String inputStr){ StringTokenizer stk = new StringTokenizer(inputStr, ","); ArrayList list = new ArrayList(); int lineNum = 0; while(stk.hasMoreTokens()){ String s = stk.nextToken(); list.add(s); lineNum ++; } Object[] o = list.toArray(); int leng = o.length; String[] reStr = new String[leng] ; for(int i=0;i<o.length;i++){ reStr[i] = o[i].toString(); } return reStr; } 方法3 public static String[] readConfig(String inputStr){ StringTokenizer stk = new StringTokenizer(inputStr, ","); ArrayList list = new ArrayList(); int lineNum = 0; while(stk.hasMoreTokens()){ String s = stk.nextToken(); list.add(s); lineNum ++; } String[] a = new String[lineNum]; return (String[])list.toArray(a); }

你可能感兴趣的:(String,list,object)