How to read and process CSV file in Java? (with Streams)

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ต.ค. 2024

ความคิดเห็น • 16

  • @maankhurana5814
    @maankhurana5814 3 หลายเดือนก่อน +1

    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

  • @grrlgd3835
    @grrlgd3835 6 หลายเดือนก่อน

    excellent. to the point. really good

  • @sachinpise4233
    @sachinpise4233 2 ปีที่แล้ว +2

    Excellent

  • @alfredabate3176
    @alfredabate3176 ปีที่แล้ว

    Thanks so much

  • @ganeshk8682
    @ganeshk8682 2 ปีที่แล้ว +2

    Nice

  • @tvnathreviews
    @tvnathreviews 2 ปีที่แล้ว +1

    Is it possible to first filter lines and then map to Car object?

    • @TechRecipesTR
      @TechRecipesTR  2 ปีที่แล้ว

      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.

  • @alokranjan4587
    @alokranjan4587 2 ปีที่แล้ว +1

    Thankyou

  • @awff6416
    @awff6416 ปีที่แล้ว

    great! but I wonder how to save each object in an array?

    • @awff6416
      @awff6416 ปีที่แล้ว

      or perhaps to an arraylist

    • @TechRecipesTR
      @TechRecipesTR  ปีที่แล้ว

      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());

  • @XSource100
    @XSource100 2 ปีที่แล้ว +1

    what if some lines or some data are empty ?

    • @TechRecipesTR
      @TechRecipesTR  2 ปีที่แล้ว

      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.

    • @srishagrao
      @srishagrao ปีที่แล้ว

      Can you please share that code piece to check, if field is empty? And to ignore that field

  • @vaishnavisongirkar3621
    @vaishnavisongirkar3621 2 ปีที่แล้ว

    Can you please share pom.xml

    • @TechRecipesTR
      @TechRecipesTR  2 ปีที่แล้ว

      There is GitHub link in video description. It has all the code with pom.xml. Pleaee check.