首页 > 解决方案 > 如何将行放入字符串 ArrayList?

问题描述

我正在尝试制作一个程序,教师可以在 csv 文件中给出或更改学生的分数。

我想出了如何到达一列,但现在我需要到达一行,以便程序可以询问你想为这个标准放置什么标记。

我想将行放入String Arraylist,然后与pattern.matches()方法一起使用,但我不知道该怎么做。

这是它的样子:

这是我的专栏代码

    BufferedReader br = new BufferedReader(new FileReader("project.csv"));
    while ((line = br.readLine()) != null) {
        String[] cols = line.split(",");
    }

标签: javaarrayscsvarraylisttry-catch

解决方案


如何array在新数组中创建新数据并将修改后的数据存储起来?

像这样的东西:

BufferedReader br = new BufferedReader(new FileReader("project.csv"));
while ((line = br.readLine()) != null) {
    String[] cols = line.split(",");

Scanner in = new Scanner(System.in);
int subjectToGiveMark = in.nextInt(); // for creativity is 2
int mark = in.nextInt(); // which mark should be given 
final int size = cols.length; 
String[] finalResult = new String[size]; 
int index = 0;


while(index<finalResult.length ) {
    if (index==subjectToGiveMark) {
      finalResult[index]= String.valueOf(mark);
    } else {
    finalResult[index]=cols[index];
    }
    index++; 

}

推荐阅读