col1 col2 col3
abc 22 rome
xyz 11 spain
rome 12 uae
want to read this text file, every column values as individual objects to compare between any two object of those column.
here is my code, suggest some proper modification
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication3;
import java.util.*;
import java.io.*;
public class JavaApplication3 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException {
try{
Scanner s = new Scanner(new FileReader("exemple_1.txt"));
List<String> ls1 = new ArrayList<String>(); /* to store ClosedSet values */
List<String> ls2 = new ArrayList<String>(); /* to store Support values */
List<String> ls3 = new ArrayList<String>(); /* to store ObjectList vaules */
while(s.hasNext()){
String[] str = s.next().split("\t");
String s1 = str[0].trim(); /* takes ClosedSet vaues to read */
String s2 = str[1].trim(); /* takes Support vaues to read */
String s3= str[2].trim(); /* takes ObjectList vaues to read */
if(!"Col1".equals(s1)){ /* skip first line */
ls1.add(s1);
}
if(!"col2".equals(s2)){ /* skip first line */
ls2.add(s2);
}
if(!"col3".equals(s3)){ /* skip first line */
ls3.add(s3);
}
}
System.out.println(ls2); /* print support values */
}catch (FileNotFoundException e) {
e.printStackTrace();
} /* catch (IOException ex) {
ex.printStackTrace();
} */
}
}