我已經看到相同標題的其他問題,但它不是同一個問題。 我想將包含在數組中的字符串轉換爲數組本身。如何將字符串轉換爲數組中的字符串數組
所以我有這樣的:
String str = "hello";
那我能轉成一個字符串數組與此:
String[] arr = str.split("");
其中給出{"h", "e", "l", "l", "o"}
所以我比如把它變成一個對象數組,其中每個對象都是一個字符串數組。 這樣我就可以撥打h[0]
(之前的初始化),如System.out.println(h[0])
。
我認爲這不是很清楚,因爲我不是英語母語的人,所以我會很樂意提高我的解釋。
編輯:比如我初始化
String[] h = {"* *",
"* *",
"*****",
"* *",
"* *"};
和所有的先於其他「字母」,最終我想
for (int l=0; l<str.lenght(); l++) {
//Do what I explained above which would return the array letter = h (also the array)
for (int s=0; s<5; s++) {
System.out.println(letter[i]);
}
}
,並且輸出顯示「你好」的字符打印*由*的char。
你能提供所需的一個或兩個輸入和輸出的爲例你想要做什麼? – emiliopedrollo
那麼你只是在尋找一個雙字符串數組,比如'String [] [] doubeArr;'? – nhouser9
你不能用Java來做到這一點。 (請參閱http://stackoverflow.com/questions/8631935/creating-a-variable-name-using-a-string-value)。 – azurefrog