Skip to content
Advertisement

Tag: java-8

Java 8 modify stream elements

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 way of doing

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_home which shows me /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home however within my Library folder, there is

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 duplicated in mapGlobal and mapAdded, both

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 a Java equivalent for a Map<String, List<Tag>> that would yield a Stream<Tag>? Answer You’re looking

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 client needs to make multiple service calls and when we use Futures (Java) Future.get() will be executed sequentially…would

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 ready for a down stream consumer which doesn’t

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.BASE64Decoder to Java 8 MIME Base64 Encoder/Decoder for any existing other client code transparently. What I think so far and why Based

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 with Files.newBufferedReader() an exception is thrown. This code has this result: Is this documented?

Advertisement