Skip to content

Tag: java-stream

How to convert a CSV file to List<Map>

I have a CSV file which has a header in the first line. I want to convert it to List<Map<String, String>>, where each Map<String, String> in the list represents a record in the file. The key of the map is the header and the value is the actual value of the field. What I have so far: What fur…

Java 8 stream short-circuit

Reading up a bit on Java 8, I got to this blog post explaining a bit about streams and reduction of them, and when it would be possible to short-circuit the reduction. At the bottom it states: Note in the case of findFirst or findAny we only need the first value which matches the predicate (although findAny i…

Java 8 filter with method call

I am learning Java 8 lambda and streams and trying some examples. But facing problem with it. here is my code Am getting compilation error in .map addr(second argument) field. what wrong in it and could you please provide links to learn java 8 streams. FYI am following this link Java 8 lambda Answer The first…

How to sum a list of integers with java streams?

I want to sum a list of Integers. It works as follows, but the syntax does not feel right. Could the code be optimized? Answer This will work, but the i -> i is doing some automatic unboxing which is why it “feels” strange. mapToInt converts the stream to an IntStream “of primitive int-va…