//convert the comma separated numeric string into the array of int.
public class HelloWorld
{
public static void main(String[] args)
{
// line is the input which have the comma separated number
String line = "1,2,3,1,2,2,1,2,3,";
// 1 > split
String[] inputNumber = line.split(",");
// 1.1 > declare int array
int number []= new int[10];
// 2 > convert the String into int and save it in int array.
for(int i=0; i<inputNumber.length;i++){
number[i]=Integer.parseInt(inputNumber[i]);
}
}
}
這是它們的更好的解決方案嗎?請提出建議,或者這是做到這一點的唯一最佳解決方案。如何將數字逗號分隔的字符串轉換爲int數組
這個問題的主要目的是找到最好的解決方案。
注:這個問題已經被[交叉張貼在代碼審查(http://codereview.stackexchange.com/q/121756/9357)。 (沒關係,但是請向其他用戶聲明交叉帖子。) –