Thanks a lot brother 😊 How to Write function “validateYear” that validates a user entry against predefined data, and returns “OK” if it is valid data, or one of two error messages
you can use Collectors.toList() to collect into a List of Car objects. something like below would help. List cars = Files.lines(path) .skip(1) .map(CSVFileStream::getCar) .collect(Collectors.toList());
Thanks a lot brother 😊
How to Write function “validateYear” that validates a user entry against predefined data, and returns “OK” if it is valid data, or one of two error messages
excellent. to the point. really good
Excellent
Thanks so much
Nice
Is it possible to first filter lines and then map to Car object?
Yes. But then you will have a String of CSV line and not the Car object and will have to filter by using the contains method of string class.
Thankyou
great! but I wonder how to save each object in an array?
or perhaps to an arraylist
you can use Collectors.toList() to collect into a List of Car objects. something like below would help.
List cars = Files.lines(path)
.skip(1)
.map(CSVFileStream::getCar)
.collect(Collectors.toList());
what if some lines or some data are empty ?
You can add a filter to check if. The line or field is empty. Based on the use case you can choose to throw the error or ignore the line.
Can you please share that code piece to check, if field is empty? And to ignore that field
Can you please share pom.xml
There is GitHub link in video description. It has all the code with pom.xml. Pleaee check.