java-8 Questions
6
Solved
How can I elegantly serialize a lambda?
For example, the code below throws a NotSerializableException. How can I fix it without creating a SerializableRunnable "dummy" interface?
public static vo...
Selfdefense asked 2/4, 2014 at 10:2
7
Solved
Use Case
Through some coding Katas posted at work, I stumbled on this problem that I'm not sure how to solve.
Using Java 8 Streams, given a list of positive integers, produce a
list of integer...
Napolitano asked 7/5, 2015 at 0:8
5
Solved
I have the following qustion:
How can I convert the following code snipped to Java 8 lambda style?
List<String> tmpAdresses = new ArrayList<String>();
for (User user : users) {
tmpAd...
Carrew asked 8/8, 2018 at 13:14
7
How can I convert a java.util.Date to String using
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss")
The Date object which I get is passed
DateTime now ...
Naresh asked 13/2, 2017 at 17:46
5
Solved
I have a problem with the stream of Java 8 foreach attempting to move on next item in loop. I cannot set the command like continue;, only return; works but you will exit from the loop in this case....
3
Solved
I'm using Spring Boot and I want to get resources.
Here's my directory structure:
├───java
│ └───...
├───resources
│ └───files
│ ├───file1.txt
│ ├───file2.txt
│ ├───file3.txt
│ └───file4.txt
I'...
13
Solved
Map<String, String> phoneBook = people.stream()
.collect(toMap(Person::getName,
Person::getAddress));
I get java.lang.IllegalStateException: Duplicate key when a duplicated element is fou...
Oscillogram asked 31/8, 2015 at 13:49
7
I have a project that has started throwing this error when building in Android Studio or Gradle:
com.android.tools.r8.ApiLevelException: MethodHandle.invoke and MethodHandle.invokeExact are only s...
5
Solved
I know that:
Instant is rather a "technical" timestamp representation (nanoseconds) for computing.
LocalDateTime is rather date/clock representation including time-zones for humans.
Sti...
13
Solved
I am struggling for the past 6-7 hrs trying to figure out what went wrong with my Apache Tomcat Server. In all of my projects, the jdk version got switched to 1.6 from 1.8.
To solve the version c...
3
Solved
I have little problem with code design that use new streaming API from Java 8. I would like to learn new things and one of the task is:
Reject max and min from list. List not contains duplicates.
...
Dusa asked 7/4, 2014 at 11:25
10
Solved
I am trying to understand the difference between the Optional<T>.orElse() and Optional<T>.orElseGet() methods.
The description for the orElse() method is "Return the value if present,...
Anabiosis asked 16/10, 2015 at 12:5
26
Java 8 introduced lambda functions and I want to implement something like factorial:
IntToDoubleFunction fact = x -> x == 0 ? 1 : x * fact.applyAsDouble(x-1);
Compilation returns
error: va...
6
Solved
I am writing a function to convert array to Map using Java 8 Stream.
Here is what I wanted
public static <K, V> Map<K, V> toMap(Object... entries) {
// Requirements:
// entries must...
Undermanned asked 30/1, 2017 at 22:12
3
I'm trying to implement a stream that uses another instance of itself in its implementation. The stream has a few constant elements prepended (with IntStream.concat) to it, so this should work as l...
Slit asked 6/7, 2015 at 19:26
5
Solved
I am trying to convert a string in OffsetDateTime but getting below error.
java.time.format.DateTimeParseException: Text '20150101' could not be parsed: Unable to obtain OffsetDateTime from Tempor...
15
Solved
I'm playing with lambdas in Java 8 and I came across warning local variables referenced from a lambda expression must be final or effectively final. I know that when I use variables inside anonymou...
Nikos asked 5/1, 2014 at 19:30
3
Solved
I have the following code using java Stream.
I am trying the get the function to build a string of value: "a,b" in this case.
however, the output (separatedByComma in this case) is always "b".
Co...
Haig asked 14/11, 2018 at 8:20
12
Solved
I am trying to calculate the difference between two LocalDateTime.
The output needs to be of the format y years m months d days h hours m minutes s seconds. Here is what I have written:
import j...
Boysenberry asked 9/9, 2014 at 14:41
5
Solved
I am working on java application where i am using Java 8.
I have integrated the database(multiple database Oracle, Mysql, Postgres) and where in DB i string the created date.
the date format in DB ...
5
Solved
I have been working on java 7 so far and recently moved to java-8, one thing which was surprising is that you can add methods in java-8 interfaces.
So far so good....loved this new stuff!
Now, my p...
4
How can one get the distinct (distinct based on two property) list from a list of objects.
for example let there are list of objects with property name and price.
Now how can I get a list with dist...
Evalyn asked 15/3, 2017 at 18:28
7
Solved
This may sounds like a strange question, but is there a way to refer to a standard no-op (aka null operation, null-pattern method, no-operation, do-nothing method) method for a Lambda in Java 8.
C...
Nub asked 24/4, 2015 at 15:28
10
Solved
I can't change the java version in macOS BigSur.
i have the following versions :
when I execute this command
/usr/libexec/java_home -V
i have the following versions :
Matching Java Virtual Machine...
13
Solved
I want to sum a list of Integers. It works as follows, but the syntax does not feel right. Could the code be optimized?
Map<String, Integer> integers;
integers.values().stream().mapToInt(i -&...
Transatlantic asked 8/5, 2015 at 13:39
© 2022 - 2024 — McMap. All rights reserved.