如何替换 2D java arraylist 中的空元素?



我打算用类似或 NA 的前导/尾随元素值替换ArrayList中的空元素。该程序在运行的初始步骤中返回false,因此我无法继续实现它。我做错了什么?请为我建议一个合适的方法,谢谢

File file=new File("file1.csv");
Scanner inputStream;
List<String> header = null; //Store the header in a separate list
List<List<String>> lines = new ArrayList<>();
try{
inputStream = new Scanner(file);
while(inputStream.hasNext()){
String line= inputStream.next();
String[] values = line.split(",");
if (header == null){
header= Arrays.asList(values);
continue;//go to the next line as header is read
}
// Adds the currently parsed line 
lines.add(Arrays.asList(values));
}
inputStream.close();
}catch (FileNotFoundException e) {
e.printStackTrace();
}
//fails; outputs "false"
System.out.println(lines.removeAll(Arrays.asList(Arrays.asList(" "))));
//test on 1D arraylist- successful
List<String> colors = new ArrayList<>(Arrays.asList("R", " ", "G", " ", "B"));
colors.removeAll(Arrays.asList(" "));
System.out.println(colors);   
// OTHER part of program ..., file2 is expected results   

file1

ID  577 592 598 600 612 650 700 822 825 830 840 870
Line0   A           A                   A           A
Line1   B           B                   NA          B
Line2   B           A                   A           A

file2

ID  577 592 598 600 612 650 700 822 825 830 840 870
Line0   A   A   A   A   A   A   A   A   A   A   A   A
Line1   B   B   B   B   NA  NA  NA  NA  NA  NA  NA  B
Line2   B   NA  NA  A   A   A   A   A   A   A   A   A

也许String[] values = line.split(",");行是错误的,我在输入文件中看不到任何,

最新更新