用java将字符串存入数组

我想将一个temp1[]和temp2[]的字符串存入temparray[1][]的二维数组中并且中间隔一个空格,请问有这样的函数么

一行存入一个数组吗?

String[] array;
string str;
int i;
FileReader word = new FileReader("word.txt");
BufferedReader br = new BufferedReader(word);
while((str = br.readLine()) != null){
    array[i] = str;
    i++;
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-05-14
您好,可以先全部读入,作为字符串str,然后将字符从字符传中取出,一个个的赋值给数组chs[].如下程序所示:
import java.util.Scanner;
public class StrIn
{
public static void main(String[] args)
{
char[] chs = new char[100];
String str;
Scanner sc = new Scanner(System.in);
System.out.print("请输入字符串:");
str = sc.nextLine();
System.out.println();
for (int i = 0; i < str.length(); i ++)
{
chs[i] = str.charAt(i);
System.out.print(chs[i] + " ");
}
}
}本回答被网友采纳
相似回答