As far as i know, you can only read the data from file in row wise, there is not any mechanism to read the file vertically. But i have a solution for it, read the whole file, You can create a array of students and initialize it with default constructor and then set the data while reading downwards row wise.

try {
        BufferedReader reader = new BufferedReader(new FileReader("file.csv"));

        // Reading first line..
        String[] names = reader.readLine().split(",");
        // Execpt 'names' there are total 4 students, A,B,C,D.
        int totalStudents = names.length - 1;
        StudentVO[] array = new StudentVO[totalStudents];
        // Initialize all students with default constructor.
        for(int i = 0; i < array.length; i++) {
            array[i] = new StudentVO();
        }

        //////////////
        // Start reading other data and setting up on objects..
        // Line 2..
        String[] joinDates = reader.readLine().split(",");
        // i = 0 gives us the string 'joinDates' which is in the first column.
        // so we have to skip it and start it from i = 1
        for(int i = 1; i < joinDates.length; i++) {
            // setting the objects data..
            array[i - 1].setJoinDate(joinDates[i]); 
        }

        // And keep on doing this until SecondLang_Marks..

        reader.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

This is the best way to do it for this solution according to the me.

Answer from Rehan Javed on Stack Overflow
๐ŸŒ
Mkyong
mkyong.com โ€บ home โ€บ java โ€บ how to read and parse csv file in java
How to read and parse CSV file in Java - Mkyong.com
December 26, 2020 - 3.1 This example read a CSV file and map it to a Country object via the @CsvBindByPosition.
Discussions

Reading CSV into objects
For examples showing the use of a library, I'd like to see more actual use of the information extracted from the CSV files. I'd also avoid using Lombok or similar tools as they hide some things that might need to be more explicit, e.g., the toString. I'd also use a much smaller CSV example file, unless you're doing benchmarks or performance tests. I'd also personally be interested in a comparison between the two: why choose Open CSV vs. Jackson CSV? Might be better for a blog post than a GitHub repo. More on reddit.com
๐ŸŒ r/learnjava
9
12
February 29, 2020
Java API to make an object from a CSV file - Stack Overflow
Otherwise if you decide that a new name better fits a given field, but you have already given your CSV format to a client you can no longer change your object member names (not without savage hacking anyway ...) :) ... JSefa allow you to annotate Java classes that can be used in a serialization ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
java - How to easily process CSV file to List<MyClass> - Stack Overflow
This is simple enough for my taste, ... just read the file using the above 2 lines. ... Sign up to request clarification or add additional context in comments. ... Save this answer. ... Show activity on this post. There are lot of good frameworks written in Java to parse a CSV file and form a List of Objects... More on stackoverflow.com
๐ŸŒ stackoverflow.com
java - Reading from CSV file and create object - Stack Overflow
I'm a complete beginner to Java and I have been given an exercise where I have to read data from a CSV file and then create an object for each line of the file as the program reads the data from th... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Java67
java67.com โ€บ 2015 โ€บ 08 โ€บ how-to-load-data-from-csv-file-in-java.html
How to load data from CSV file in Java - Example | Java67
You can load data from a CSV file in a Java program by using BufferedReader class from the java.io package. You can read the file line by line and convert each line into an object representing that data.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnjava โ€บ reading csv into objects
r/learnjava on Reddit: Reading CSV into objects
February 29, 2020 -

I'm pretty new to using Java as a developer. I have used java in the past, but only for my college CS classes which happened years and years ago (possibly Java v1.3?). I created a couple of examples of reading CSVs into objects using the opencsv and jackson libraries.

I'm posting these projects here to 1) get some feedback, 2) possibly help someone else who needs to read a CSV into their app.

  • opencsv-example

  • jackson-csv-example

Is there anything I can improve upon? If so, what? If either of these projects are helpful to you, let me know!

๐ŸŒ
Quora
quora.com โ€บ How-can-we-read-data-from-a-CSV-file-into-an-object-in-Java
How can we read data from a CSV file into an object in Java? - Quora
Answer (1 of 2): Please don't. It's not the 1990s anymore. We have better ways of serializing structured data than CSV files. Use one of the mainstream interface description languages to automatically generate strongly typed object representations and mappings to and from various serialization fo...
๐ŸŒ
My Developer Journal
sunitc.dev โ€บ 2020 โ€บ 05 โ€บ 31 โ€บ read-csv-file-to-java-bean-using-open-csv
Read CSV File to Java Bean (using Open CSV) โ€“ My Developer Journal
April 22, 2021 - In this article we will look at how to read CSV files into Java objects. We will be using OpenCSV library to do the conversions, and look at some examples of how we can customize it based on requirement. 1. Pre-requisite In this article we will me use of Gradle to import the package dependenciesโ€ฆ
Find elsewhere
๐ŸŒ
Dirask
dirask.com โ€บ posts โ€บ Java-how-to-read-CSV-file-into-java-object-using-Jackson-CSV-library-complex-example-with-BigDecimal-and-enum-x1Rm7j
Java - how to read CSV file into java object using Jackson CSV library - complex example with BigDecimal and enum
import com.fasterxml.jackson.databind.MappingIterator; import com.fasterxml.jackson.dataformat.csv.CsvMapper; import com.fasterxml.jackson.dataformat.csv.CsvSchema; import java.io.File; import java.io.IOException; import java.util.List; public class ComplexUserCsvReader { public static void main(String[] args) throws IOException { // set correct path to csv file on your disc File csvFile = new File("C:\\csv_tests\\complex_users.csv"); CsvMapper csvMapper = new CsvMapper(); CsvSchema csvSchema = csvMapper .typedSchemaFor(ComplexUserDto.class) .withHeader() .withColumnSeparator(',') .withComment
๐ŸŒ
Blogger
atozjavatutorials.blogspot.com โ€บ 2015 โ€บ 06 โ€บ read-data-from-csv-file-and-map-it-to.html
Read the data from CSV file and Map it to java object in java. | a2z java tutorials
String csvFilename = "D:\\Ashish\\Personal\\WebApplication1\\worldcup.csv"; CSVReader csvReader = new CSVReader(new FileReader(csvFilename)); Step 7- Call csv.parse(strat, csvReader) method and get List object with all the data. Step 8- Iterate this list and get Country class object Country ...
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java io โ€บ reading a csv file into an array
Reading a CSV File into an Array | Baeldung
May 9, 2025 - Alternatively, we can use the Files class to achieve the same objective. This utility class consists of several static methods that operate on files and directories. So, letโ€™s see how to use it in practice. The lines() method is one of the enhancements introduced in Java 8. It allows us to read all lines of a given file as a stream. So, letโ€™s see it in action: try (Stream<String> lines = Files.lines(Paths.get(CSV_FILE))) { List<List<String>> records = lines.map(line -> Arrays.asList(line.split(COMMA_DELIMITER))) .collect(Collectors.toList()); }
๐ŸŒ
YouTube
youtube.com โ€บ watch
Read and Parse CSV file in Java POJO Object - YouTube
If you have any query then ask me in the comment section.Like and Share my video.Subscribe my Channel "/ Code" and click on the bell for notification of my n...
Published ย  July 7, 2019
๐ŸŒ
How to do in Java
howtodoinjava.com โ€บ home โ€บ i/o โ€บ parse and read a csv file in java
Parse and Read a CSV File in Java
September 14, 2022 - We can use a separate Scanner to read lines, and another scanner to parse each line into tokens. This approach may not be useful for large files because it is creating one scanner instance per line.
๐ŸŒ
Javatpoint
javatpoint.com โ€บ how-to-read-csv-file-in-java
Read CSV File in Java
How to Read CSV File in Java with oops, string, exceptions, multithreading, collections, jdbc, rmi, fundamentals, programs, swing, javafx, io streams, networking, sockets, classes, objects etc,
๐ŸŒ
Blogger
javarevisited.blogspot.com โ€บ 2015 โ€บ 06 โ€บ 2-ways-to-parse-csv-files-in-java-example.html
2 Ways to Parse CSV Files in Java - BufferedReader vs Apache Commons CSV Example
August 7, 2021 - Our CSV file - countries.txt NAME,CAPITAL,CURRENCY India,New Delhi,INR USA,Washington,USD England,London,GBP Japan,Tokyo,JPY There are two methods in this program readCSV() and parseCSV(), former uses BufferedReader to read CSV file.
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ reading-and-writing-csvs-in-java
Reading and Writing CSVs in Java
February 20, 2019 - However, not all programs require all of those features, so it is still important to be able to handle CSV files with core Java, without the use of any additional libraries. A simple combination of FileReader, BufferedReader, and String.split() can facilitate reading data from CSVs.
Top answer
1 of 7
17

One of the simplest ways to read and serialize data is by using the Jackson library. It also has an extension for CSV, you can find the wiki here

Let's say you have a Pojo like this:

@JsonPropertyOrder({ "name", "surname", "shoesize", "gender" })
public class Person {

    public String name;
    public String surname;
    public int shoesize;
    public String gender;

}

And a CSV like this:

Tom,Tommy,32,m
Anna,Anny,27,f

Then reading it is done like so:

MappingIterator<Person> personIter = new CsvMapper().readerWithTypedSchemaFor(Person.class).readValues(csvFile);
List<Person> people = personIter.readAll();

This is simple enough for my taste, basically all you need to do is add the column order in your CSV file using the @JsonPropertyOrder annotation and then just read the file using the above 2 lines.

2 of 7
10

There are lot of good frameworks written in Java to parse a CSV file and form a List of Objects. OpenCSV, JSefa & jCSV are to name a few of them.

For your requirement, I believe jCSV suits the best. Below is the sample code from jCSV which you can make use of easily.

Reader reader = new FileReader("persons.csv");

CSVReader<Person> csvPersonReader = ...;

// read all entries at once
List<Person> persons = csvPersonReader.readAll();

// read each entry individually
Iterator<Person> it = csvPersonReader.iterator();
while (it.hasNext()) {
  Person p = it.next();
  // ...
}

Moreover, parsing a CSV file and converting it to a List isn't a big deal and it can be achieved without using any framework, as shown below.

br = new BufferedReader(new FileReader(csvFileToRead));  
List<Person> personList = new ArrayList<>();
while ((line = br.readLine()) != null) {  
       // split on comma(',')  
       String[] personCsv = line.split(splitBy);  

       // create car object to store values  
       Person personObj = new Person();  

       // add values from csv to car object  
       personObj.setName(personCsv[0]);  
       personObj.setSurname(personCsv[1]);  
       personObj.setShoeSize(personCsv[2]);  
       personObj.setGender(personCsv[3]); 

       // adding car objects to a list  
       personList.add(personObj);         
} 

If the mapping of CSV columns to bean object is complex, repetitive or large in real case scenario, then it can be done easily by using DozerBeanMapper.

Hope this will help you.

Shishir

๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 64488594 โ€บ reading-from-csv-file-and-create-object
java - Reading from CSV file and create object - Stack Overflow
This case brings us to the third solution with setters and getters. The variables that describe the Client are already defined, it is possible to pass them to assemble the perfect object, but it is not possible to retrieve them.
๐ŸŒ
CalliCoder
callicoder.com โ€บ java-read-write-csv-file-opencsv
Read / Write CSV files in Java using OpenCSV | CalliCoder
February 18, 2022 - In the above example, we obtained an Iterator from csvToBean object, and then looped through this iterator to retrieve every object one by one. The CsvToBean class also provides a parse() method which parses the entire CSV file and loads all the objects at once into memory. You can use it like so - // Reads all CSV contents into memory (Not suitable for large CSV files) List<CSVUser> csvUsers = csvToBean.parse(); for(CSVUser csvUser: csvUsers) { System.out.println("Name : " + csvUser.getName()); System.out.println("Email : " + csvUser.getEmail()); System.out.println("PhoneNo : " + csvUser.getPhoneNo()); System.out.println("Country : " + csvUser.getCountry()); System.out.println("=========================="); }