Storing .csv file data into the hashMap

              Storing .csv file data into the hashMap




public class App {


    public static void main(String args[])
    {
        String csvFilePath="C:\\Users\\kalas\\OneDrive\\Desktop\\Student.csv";
        try {
            BufferedReader lineRead=new BufferedReader(new FileReader(csvFilePath));
            CSVParser records=CSVParser.parse(lineRead,CSVFormat.EXCEL.withFirstRecordAsHeader().withIgnoreHeaderCase().withTrim());
            Map<Integer,Student> studentMap=new HashMap<Integer, Student>();
            for(CSVRecord record:records)
            {
                Student student=new Student();
                student.setStudentId(Integer.parseInt(record.get(0)));
                student.setStudentName(record.get(1));

                studentMap.put(Integer.parseInt(record.get(0)),student);
            }

            System.out.println(studentMap);

           Collection collection= studentMap.values();
           Iterator iterator=collection.iterator();
           while(iterator.hasNext()!=false)
           {
               Student student= (Student) iterator.next();
               System.out.println(student.getStudentId()+"   "+student.getStudentName());
           }


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


********************************RELATED VIDEOS***********************


Reading .CSV File:-



Installing MysqlWorkbench:-



Creating Hibernate Project:-
















No comments

Powered by Blogger.