Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.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_Json_Couchdb - Fatal编程技术网

Java 如何在读取csv文件时跳过重复的行?

Java 如何在读取csv文件时跳过重复的行?,java,json,couchdb,Java,Json,Couchdb,我需要跳过csv文件中的重复项,并需要将原始值插入我的数据库。 这是我的密码 public class Json { public List<User> jsonConvert() throws JsonGenerationException, JsonMappingException, IOException { File input = new File("C:\\Users\\SwedhaS\\Documents\\Sam

我需要跳过csv文件中的重复项,并需要将原始值插入我的数据库。 这是我的密码

public class Json {
    public List<User> jsonConvert()
                throws JsonGenerationException, JsonMappingException, IOException {
        File input = new File("C:\\Users\\SwedhaS\\Documents\\SametimeFileTransfers\\newPIRs.csv");      

        Pattern pattern = Pattern.compile(",");

        try (BufferedReader in = new BufferedReader(new FileReader(input));) {
            List<User> users = in 
                .lines()
                .skip(1)
                .<User>map(line -> {
                    String[]x = new String[6];
                    x = pattern.split(line);
                    return new User(x);
                }).collect(Collectors.toList());

            ObjectMapper mapper = new ObjectMapper();
            mapper.enable(SerializationFeature.INDENT_OUTPUT);
            mapper.writeValue(System.out, users);

            return users;
        }
    }
}
公共类Json{
公共列表jsonConvert()
抛出JsonGenerationException、JsonMappingException、IOException{
文件输入=新文件(“C:\\Users\\SwedhaS\\Documents\\SametimeFileTransfers\\newPIRs.csv”);
Pattern=Pattern.compile(“,”);
try(BufferedReader in=new BufferedReader(new FileReader(input));){
列出用户=in
.行()
.skip(1)
.map(行->{
字符串[]x=新字符串[6];
x=图案。分割(线);
返回新用户(x);
}).collect(Collectors.toList());
ObjectMapper mapper=新的ObjectMapper();
enable(SerializationFeature.INDENT_输出);
mapper.writeValue(System.out,用户);
返回用户;
}
}
}

我相信您正在尝试从
用户列表中删除重复项,对吗

为此,如果您还想保留顺序,可以使用哈希集,它会自动删除重复项:

Set<String> usersSet = new LinkedHashSet<>(users);
Set usersSet=newlinkedhashset(用户);

我相信您正在尝试从
用户列表中删除重复项,对吗

为此,如果您还想保留顺序,可以使用哈希集,它会自动删除重复项:

Set<String> usersSet = new LinkedHashSet<>(users);
Set usersSet=newlinkedhashset(用户);

假设
equals
hashcode
用户
中正确实现,尝试用
集合
替换
列表
(参见
收集器.toSet()
)。假设
equals
hashcode
用户
中正确实现,尝试将
列表
替换为
集合
(参见
收集器.toSet()
)。