java - delete Row in a CSV file -


delete rows based on duplicate column in csv file eg., csv file contains.

campaigncode | cellcode     | startdate   | phone| account c000001413   |  a000363363  |  20170601   | 4167292999  | 999999999 c000001414   |  a000363364  |  20170601   | 4167292999  | 999999999 

here want delete complete row based on phone column duplicates. expected output is: campaigncode | cellcode | startdate | phone | account c000001413 | a000363363 | 20170601 | 4167292999 | 999999999

solution read csv file line line, put each line list , check duplicate @ column want => write down list of new line current file. sample code (i'm using comma seperate instead of |)

public class csvreader {     public static void main(string[] args) throws ioexception {          string csvfile = "csv.csv";         bufferedreader br = null;         string line = "";         string cvssplitby = ",";         list<string> lines = new arraylist<string>();         boolean isduplicate = false;          br = new bufferedreader(new filereader(csvfile));         while ((line = br.readline()) != null) {             isduplicate = false;             string[] object = line.split(cvssplitby);             (string l : lines) {                 if (l.contains(object[3])) {                     isduplicate = true;                     break;                 }             }             if (!isduplicate) {                 lines.add(line);             }         }         (string newl : lines) {             system.out.println(newl);         }         br.close();     } } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -