java - 如何将行放入字符串 ArrayList?
问题描述
我正在尝试制作一个程序,教师可以在 csv 文件中给出或更改学生的分数。
我想出了如何到达一列,但现在我需要到达一行,以便程序可以询问你想为这个标准放置什么标记。
我想将行放入String Arraylist,然后与pattern.matches()
方法一起使用,但我不知道该怎么做。
这是它的样子:
这是我的专栏代码
BufferedReader br = new BufferedReader(new FileReader("project.csv"));
while ((line = br.readLine()) != null) {
String[] cols = line.split(",");
}
解决方案
如何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++;
}
推荐阅读
- c# - JsonUtility 返回一个空列表
- javascript - 无法从“App.js”解析“react-redux”
- angular - 将自定义组件与材料设计组件分开导入时,Angular7按钮不呈现
- java - SwipeRefreshLayout Circle 在刷新期间滞后
- html - 为什么我不能更改导航栏上的字体系列?
- python - 如何计算列中使用的前 3 个单词并将结果存储在字典中
- python - 如何在 django 模板中声明一个变量并在 if 条件下更改该变量的值?
- python - datetime.strptime: TypeError: strptime() argument 1 must be str, not Series
- web-services - 使用 post httpClient ionic 发送数组字符串
- typescript - 打字稿地图迭代给出错误map.keys不是云函数中的函数