Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何控制比较器以避免内部的&引用;在csv文件中_Java_Sorting_Comparator - Fatal编程技术网

Java 如何控制比较器以避免内部的&引用;在csv文件中

Java 如何控制比较器以避免内部的&引用;在csv文件中,java,sorting,comparator,Java,Sorting,Comparator,我试图按年龄对这些值进行排序,结果出现了一个错误。程序中有一种方法,它用“,”分隔值。在检查错误时,它似乎还考虑了字符串地址内的(不应该这样做)。关于如何使它忽略双引号内的值,有什么想法吗 下面是我拆分值的代码部分: while ((string = input.readLine()) != null) { // Reads each line and loops until there is no more text to be read String[] list = st

我试图按年龄对这些值进行排序,结果出现了一个错误。程序中有一种方法,它用“,”分隔值。在检查错误时,它似乎还考虑了字符串地址内的(不应该这样做)。关于如何使它忽略双引号内的值,有什么想法吗

下面是我拆分值的代码部分:

while ((string = input.readLine()) != null) { // Reads each line and loops until there is no more text to be read

        String[] list = string.split(",", 8); // Uses "," to split the data
        String name = list[0] + "," + list[1]; // The parts of data is assigned their specific variable
        String email = list[2];// The parts of data is assigned their specific variable
        String address = list[3];
        int age = Integer.parseInt(list[4]); // Using parseInt, the data becomes an integer so comparison will be possible
        String residency = list[5];
        int district = Integer.parseInt(list[6]);
        String gender = list[7];

        person.add(new Person(name, email, address, age, residency, district, gender)); // Passes the information from the txt file
    }

改用CSV解析器。解析带有引号和嵌入逗号的CSV并不容易。使用库(如)解析数据。如果您的目的是学习或练习,则可以使用标志
boolean isinquetes=false
。然后,您可以手动迭代字符,并在遇到
时切换标志。请注意,这不适用于嵌套引号。