java-8 Questions
7
Solved
Optional type introduced in Java 8 is a new thing for many developers.
Is a getter method returning Optional<Foo> type in place of the classic Foo a good practice? Assume that the value can ...
Panslavism asked 12/10, 2014 at 17:30
14
Solved
I see java.util.function.BiFunction, so I can do this:
BiFunction<Integer, Integer, Integer> f = (x, y) -> { return 0; };
What if that is not good enough and I need TriFunction? It does...
3
Solved
I am using Ubuntu 14.04 with Oracle JDK 8. I want to inspect performance of my application using VisualVM. I can inspect other applications like JDownloader but I can't inspect my own applications ...
5
Solved
Is there is a good way to add a new value to existing Stream? All I can imagine is something like this:
public <T> Stream<T> addToStream(Stream<T> stream, T elem ) {
List<T>...
7
Solved
I was playing with the new date time API but when running this:
public class Test {
public static void main(String[] args){
String dateFormatted = LocalDate.now()
.format(DateTimeFormatter
.o...
1
I have been using Java's CompletableFuture like this
CompletableFuture.runAsync(() -> {//Some code here });
When I try to use a Resteasy Client inside this block of code I get a
javax.ws.r...
Bcd asked 14/4, 2015 at 16:57
28
Solved
I know how to create a reference to a method that has a String parameter and returns an int, it's:
Function<String, Integer>
However, this doesn't work if the function throws an exception,...
5
Solved
I am having a boolean variable hasObject in lombok which generates isHasObject(). I am using @Data lombok annotation. How can i change the method to hasObject()
4
Solved
I'm very new to Java 8 lambdas and stuff. I want to write a lambda function that takes a JSONArray, goes over its JSONObjects and creates a list of values of certain field.
For example, a fun...
Substituent asked 16/6, 2017 at 18:4
6
Solved
Is there a sane way to get an ordered stream from a list (array list specifically, but it shouldn't matter) that streams elements in reverse of how they are in the original list?
I'm looking for a...
Gowan asked 2/4, 2015 at 1:34
3
Solved
When I do this
String datum = "20130419233512";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss").withZone(ZoneId.of("Europe/Berlin"));
OffsetDateTime datetime = OffsetDa...
3
Solved
Say I have the following code
data.stream()
.map(x -> {
Object a = maybeReturnsNull(x);
return a == null ? defaultValue : a;
})
I have some function that might be returning null, and I'm ...
Condescension asked 25/6, 2015 at 19:6
8
Solved
Just like java.util.Optional<T> in Java 8 is (somewhat) equivalent to Scala's Option[T] type, is there an equivalent to Scala's Either[L, R]?
3
Solved
If I want to run a Stream in parallel in a background task is it possible to run it in lower priority? And if so how?
Coucher asked 26/11, 2017 at 3:44
5
Solved
Which is the best way to create a stream out of a collection:
final Collection<String> entities = someService.getArrayList();
entities.stream();
Stream.of(entities);
Quigley asked 5/10, 2016 at 12:40
4
Solved
I've just replaced s in the following lambda expression by _:
s -> Integer.parseInt(s)
Eclipse compiler says:
'_' should not be used as an identifier, since it is a reserved keyword from s...
21
Solved
In Java 8, what's the difference between Stream.map() and Stream.flatMap() methods?
Coward asked 31/10, 2014 at 22:53
4
Solved
Is there any ceil counterpart for Math.floorDiv()
How to calculate it fastest way with what we have?
UPDATE
The code for floorDiv() is follows:
public static long floorDiv(long x, long y) {
l...
4
Solved
I'm new to java.time package. I have a LocalDate 2015-12-10. I need to convert this to ZonedDateTime. Time should be 00:00:00 and Zone is ZoneOffset.UTC.
After conversion, ZonedDateTime should be...
6
Solved
I had already asked a similar question here but it seems It wasn't clear since I had a lot of code in the project and couldn't post it here So please don't mark as duplicate.
Because of that, I t...
4
Solved
I'm trying to do this:
return Optional.of(myMap.getOrDefault(myKey, null));
Really, what I want is to return an Optional.of(foundVal) if found, otherwise Optional.empty(). I don't believe Option...
Eggett asked 1/11, 2018 at 20:10
6
Solved
When using the Java 8 Optional class, there are two ways in which a value can be wrapped in an optional.
String foobar = <value or null>;
Optional.of(foobar); // May throw NullPointerExcepti...
Squally asked 29/7, 2015 at 9:30
1
Could you kindly help us with a query we have regarding a Java 8 Spring boot application running in Docker containers in ECS? After migrating to Java 17, we observed a significant 1GB increase in m...
Whiffletree asked 3/5, 2023 at 7:15
5
Installed intellij and added sdk path to project structure, but when i try to run i get:
Error: Cannot run program "/home/$USER/java/jdk1.8.0_121/bin/java"
(in directory"/home/$USER/.intelliJIdea...
Greiner asked 17/3, 2017 at 11:38
5
Solved
I have a little problem with default methods in Interface and BeanInfo Introspector.
In this example, there is interface: Interface
public static interface Interface {
default public String getL...
Predecease asked 22/4, 2014 at 12:5
© 2022 - 2024 — McMap. All rights reserved.