Category "java-8"

finally block equivalent for exception handling in CompletableFuture

I have CompletableFuture which can return result or exception. I want to perform run some common code in case of exception and normal result. Similar to try cat

Collect both matching and non-matching in one stream processing?

Is there a way to collect both matching and not matching elements of stream in one processing? Take this example: final List<Integer> numbers = Arrays.as

How to access nested Json Object Value into JPA Entity Class

I have a payload like this { "eventId":"ep9_0579af51", "eventTime":"5/11/2022 5:50:58 PM", "eventType":"UpdateTransaction", "meta":{ "us

Can't obtain static method fromNative(Method, Object) from class com.sun.jna.Native

I'm using the JNA's com.sun.jna.NativeLibrary class in order to load the VLCJ native library. I'm working on an armv8(aarch x64)-based linux device. Below is my

How to check if list has more then 3 elements using Java8

I have a method that accepts a list of object. I want to iterate through that list and check if the list has more than 3 elements. If it does, I want to throw e

Tune DocLint to allow new tags in javadocs

Is there a way to tune the DocLint (-Xdoclint) to allow new tags in javadocs? Right now i get errors like: error: unknown tag: checkstyle * @checkstyle Pa

Calling default method in interface when having conflict with private method

Consider below class hierarchy. class ClassA { private void hello() { System.out.println("Hello from A"); } } interface Myinterface { defa

Is it correct to convert a CompletableFuture<Stream<T>> to a Publisher<T>?

To allow multiple iterations on the resulting stream from a CompletableFuture<Stream<String>> I am considering one of the following approaches: Con

SSLHandshakeException in Eclipse Temurin JRE8 Alpine container for self-signed certificate

TL;DR: After installing my CA in a Docker container from image eclipse-temurin:8-jre-alpine I still get javax.net.ssl.SSLHandshakeException: Received fatal aler

How to remove an element from a Set inside a Page of items based on a Condition using Java 8

I have a Page of Farmers coming from a JPA repository call findAll method. Each Farmer consists of a Set of Farms which are also coming in the repository call l

Java stream. Sum two fields in a stream of objects

I have something like this: Integer totalIncome = carDealer.getBrands().stream().mapToInt(brand -> brand.getManufacturer().getIncome()).sum(); Integer total

Jersey: Disable automatic Wadl Generation for OPTIONS request without using a web.xml file?

I want to accomplish the same thing as this question: Disable automatic Wadl Generation for OPTIONS request, but we don't have a web.xml file. We also make use

How to write Unit Test for below Exception Handler method using mockito?

@ExceptionHandler({ ConstraintViolationException.class }) public ResponseEntity<Object> handleConstraintViolation(ConstraintViolationException ex, WebRequ

How do I elegantly and safely maximize the amount of heap space allocated to a Java application in Kubernetes?

I have a Kubernetes deployment that deploys a Java application based on the anapsix/alpine-java image. There is nothing else running in the container expect for

Gc logs not printing

I pass the below value to jvms hosted on Jboss : <option value="-XX:+PrintGCDetails"/> <option v

Creating directories in Java

enter image description hereI'm very new to the Java world so please forgive my ignorance. What is the optimal way to create 1000 New directories in Java? kn

What is the fastest way to iterate on a stream in Java 8?

If I have a collection and I want to iterate over a filtered stream then I could do either of the following (and many more obtuse options): for(item in collect

Why is a parallel stream slower than a sequential stream?

I have two functions solving the same problem. The first uses a sequential stream, and the second uses a parallel stream. public static int digitalRoot(int n)

CompletableFuture | thenApply vs thenCompose

I can't get my head around the difference between thenApply and thenCompose. So, could someone provide a valid use case? From the Java docs: thenApply(Function&

How to remove Duplicated elements from a List based on Two properties using Java 8 streams?

I'm trying to figure out how to write a stream in Java 8 that removes duplicate records based on a property and a condition, for example: +----+----------------