Skip to content
Advertisement

Tag: java-8

java8 possibility to apply mathematical operators to functions

Assume, I’ve got two functions. I want to multiply these functions. So I want to get this lambda expression as a result: Is it possible in Java 8? Answer No, you won’t be able to do that with Function. Suppose you have a Function.multiply(other) method, what would be the result of performing multiplication with the two following functions? However, if

How to combine 3 or more CompletionStages?

If have 2 CompletionStages, I can combine them with thenCombine method: If I have 3 or more CompletionStages, I can make a chain of thenCombine methods, but I have to use temporary objects to pass results. For example, here is a solution using Pair and Triple from the org.apache.commons.lang3.tuple package: Is there a better way to combine results from multiple

Method Overloading – Java

Actual Question: If it calls (1) then how can I make it so that it calls (2) ? I have following methods signature Somewhere I make a call like myMethod(new String(“name”), new MyClass()); Which overloaded method will be called ? If it calls (1) then how can I make it so that it calls (2) ? Answer It will call

Conditionally add an operation to a Java 8 stream

I’m wondering if I can add an operation to a stream, based off of some sort of condition set outside of the stream. For example, I want to add a limit operation to the stream if my limit variable is not equal to -1. My code currently looks like this, but I have yet to see other examples of streams

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 further operations

Java 8: Lambda with variable arguments

I am looking for a way to invoke multiple argument methods but using a lambda construct. In the documentation it is said that lambda is only usable if it can map to a functional interface. I want to do something like: Is there any way one can do this elegantly without defining 10 interfaces, one for each argument count? Update

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 is not guaranteed

Convert a Julian Date to an Instant

I’m running into a situation where I would like to convert from a Julian date to an java.time.Instant (if that makes sense), or some Java time that can be more easily understood. My understanding of what a Julian date is comes from reading the Wikipedia page. There are bunch of different variants, and the date I am trying to read

Cannot load font in JRE 8

I cannot load a font from an S3 Inputstream in JRE 8. I do not have issue if a system is installed with JRE 7, JDK 7, or even JDK 8. The error that I got is I tried to load the inputstream to a temp file, but it does not help. I also tried to load a font directly

Advertisement