我有一个大文本文件。我想将文本文件中的每个字符放入Character数组中。我用这段代码来说明。

List<String> set = new ArrayList<String>();
BufferedReader bf = new BufferedReader(new FileReader(file_path));
String check_line=bf.readLine();
while(check_line!=null){
    set.add(check_line);
    check_line=bf.readLine();
}

ArrayList<Character> charr = new ArrayList<Character>();

for(int j=0;j<set.size();++j){
        String str=set.get(j);
        for (int x = 0; x < str.length(); x ++){
        charr.add(str.charAt(x));
        }}

return charr;


但是需要很长时间,有没有有效的方法来做到这一点?

最佳答案

您可以为每行使用

char[] x = str.toCharArray();

07-24 18:49
查看更多