DEV Community

Judy
Judy

Posted on

2 1 1 1 1

Java, fill each row having a null value in a csv file with values in the directly previous row #eg32

In the csv file below, Number column has some null values.

Image description
Task: Use Java to modify the file. The rule is like this: When a Number value is null, modify values of the current row as those of the directly previous row and save result as a new csv file.

Image description
Write the following SPL statement:

=T(""result.csv"":T(""data.csv"").(~=if(Number,~,~[-1])))

T()function reads data from or writes data to a csv file. ~ is the current record, and ~[-1] represents the directly previous record.

Read How to Call a SPL Script in Java to find how to integrate SPL into a Java application.

SPL open source address

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay