I wanted to write pure function with Java 8 that would take a collection as an argument, apply some change to every object of that collection and return a new collection after the update. I want to follow FP principles so I dont want to update/modify the collection that was passed as an argument. Is there any…
Tag: java-8
No Java folder located in Library despite JDK installation
Currently running OSX El Capitan on a recently set up computer. I’m trying to set up Java’s unlimited crypto policy which requires me to modify some files within my current jre, but I can’t find the Java folder that is supposed to be located within Library. I’ve run /usr/libexec/java_h…
How to explicitly invoke default method from a dynamic Proxy?
Since Java 8 interfaces could have default methods. I know how to invoke the method explicitly from the implementing method, i.e. (see Explicitly calling a default method in Java) But how do I explicitly invoke the default method using reflection for example on a proxy? Example: Edit: I know a similar questio…
Merge Map<String, List Java 8 Stream
I would like to merge two Map with JAVA 8 Stream: I try to use this implementation: However, this implementation only create a result like: Map<String, List<Object>> If one key is not contained in the mapGlobal, it would be added as a new key with the corresponding List of String. If the key is du…
Java Stream equivalent of LINQ SelectMany()
What’s the Java 8 Stream equivalent of LINQ’s SelectMany? For example, in C#, if I have Dictionary<string, List<Tag>> tags that I want to turn into an IEnumerable<Tag> (a flat enumerable of all the tags in the dictionary), I would do tags.SelectMany(kvp => kvp.Value). Is there…
Difference between CompletableFuture, Future and RxJava’s Observable
I would like to know the difference between CompletableFuture,Future and Observable RxJava. What I know is all are asynchronous but Future.get() blocks the thread CompletableFuture gives the callback methods RxJava Observable — similar to CompletableFuture with other benefits(not sure) For example: if c…
Does the JDK provide a dummy consumer?
I have a need in a block of code to consume ‘n’ items from a stream then finish, in essence: In my situation, I can’t change the signature to return Stream<T> and simply return stream.skip(n); I have to actually throw away some elements from the stream (not simple logic) – to be …
Is Java 8 java.util.Base64 a drop-in replacement for sun.misc.BASE64?
Question Are the Java 8 java.util.Base64 MIME Encoder and Decoder a drop-in replacement for the unsupported, internal Java API sun.misc.BASE64Encoder and sun.misc.BASE64Decoder? EDIT (Clarification): By drop-in replacement I mean that I can switch legacy code using sun.misc.BASE64Encoder and sun.misc.BASE64De…
Mapping a stream of tokens to a stream of n-grams in Java 8
I think this is a fairly basic question concerning Java 8 streams, but I have a difficult time thinking of the right search terms. So I am asking it here. I am just getting into Java 8, so bear with me. I was wondering how I could map a stream of tokens to a stream of n-grams (represented as arrays
Different results reading file with Files.newBufferedReader() and constructing readers directly
It seems that Files.newBufferedReader() is more strict about UTF-8 than the naive alternative. If I create a file with a single byte 128—so, not a valid UTF-8 character—it will happily be read if I construct an BufferedReader on an InputStreamReader on the result of Files.newInputStream(), but wit…