因此,我正在尝试对到达时间的列进行排序,以便最早到达时间排在第一位。我是java中csv文件的新手,所以挣扎着大时间。
我已经设法读取csv文件并使用数组打印,但不确定如何对特定列进行排序
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
public class readCSV {
public static void main(String[] args) {
String fileName= "csv.csv";
File file= new File(fileName);
// this gives you a 2-dimensional array of strings
List<List<String>> lines = new ArrayList<>();
Scanner inputStream;
try{
inputStream = new Scanner(file);
while(inputStream.hasNext()){
String line= inputStream.next();
String[] values = line.split(",");
// this adds the currently parsed line to the 2-dimensional string array
lines.add(Arrays.asList(values));
//System.out.println(line);
System.out.println(values[0] + ' ' + values[1] + ' ' + values[2] + ' ' + values[3] );
}
inputStream.close();
}catch (FileNotFoundException e) {
e.printStackTrace();
}
// the following code lets you iterate through the 2-dimensional array
/*int lineNo = 1;
for(List<String> line: lines) {
int columnNo = 1;
for (String value: line) {
System.out.println("Line " + lineNo + " Column " + columnNo + ": " + value);
columnNo++;
}
lineNo++;
}*/
}
}
如果有任何其他改进,例如存储csv,打印等,我很乐意更改它
下面是一个输入示例:
processID arrivalTime burstTime priority
1 0 5 1
2 1 7 2
3 0 2 1
4 2 6 2
5 6 10 3
6 5 4 4
7 6 4 7
8 5 4 8
9 6 6 3
10 6 7 2
守着一只汪
拉莫斯之舞
相关分类