java-8 Questions

2

I was iterating over some files, 5328 to be precise. These files are average XML files with 60-200 lines max. They are first filtered through a simple method isXmlSourceFile that parse the path. ...
Yeomanry asked 8/8, 2016 at 12:8

3

Solved

There are too much hype about functional programming and particularly the new Java 8 streams API. It is advertised as good replacement for old good loops and imperative paradigm. Indeed sometimes ...
Latrell asked 14/1, 2018 at 11:0

2

Solved

I was playing around with Java 8 lambdas, method references and interface default methods to explore the wonderful world of currying, and then I got this Java error I cannot understand. Here is th...
Madelenemadelin asked 27/3, 2014 at 11:43

6

Solved

I am new to java 8 and I am trying to get five years before now, here is my code: Instant fiveYearsBefore = Instant.now().plus(-5, ChronoUnit.YEARS); But I get the following error: java.time.t...
Carmencarmena asked 15/1, 2016 at 14:49

8

Solved

Stream<String> a = Stream.of("one", "three", "five"); Stream<String> b = Stream.of("two", "four", "six"); What do I need to do for the output to be the below? // one // two // thre...
Monkhmer asked 14/11, 2018 at 19:42

9

Solved

In Java, is it possible to have a lambda accept multiple different types? I.e: Single variable works: Function <Integer, Integer> adder = i -> i + 1; System.out.println (adder.apply (1...
Commines asked 10/1, 2015 at 2:52

4

Solved

I want to merge huge files containing strings into one file and tried to use nio2. I do not want to load the whole file into memory, so I tried it with BufferedReader: public void mergeFiles(files...
Rozina asked 28/8, 2014 at 10:38

2

I have a Flux and I want to convert it to List. How can I do that? Flux<Object> getInstances(String serviceId); // Current one List<Object> getInstances(String serviceId); // Demande...

7

Solved

I have one computer that I intentionally installed JDK on. I have another computer with JRE, for, among other things, testing. However, when I got a java application working on this computer, and t...
Woothen asked 20/3, 2014 at 16:47

3

Solved

I have a List<LedgerEntry> ledgerEntries and I need to calculate the sums of creditAmount and debitAmount. class LedgerEntry{ private BigDecimal creditAmount; private BigDecimal debitAmoun...
Patricio asked 22/2, 2017 at 8:25

8

Solved

Java 8 introduced java.time.Clock which can be used as an argument to many other java.time objects, allowing you to inject a real or fake clock into them. For example, I know you can create a Clock...
Elevenses asked 21/11, 2014 at 17:30

2

Solved

When I am scanning code with sonar lint the following code shows the bug as "The return value of "orElseThrow" must be used" itemList.stream() .filter(item -> orderItemId.equals(item.getId()))...
Chastise asked 28/3, 2018 at 10:43

7

Solved

I have a many objects of type Slot in an array list. Slot class is as shown below- Slot{ int start; int end; } let the list of type List<Slot> be called slots. The slots are sorted bas...
Skilling asked 24/9, 2015 at 21:43

12

Solved

Java 8 added a new java.time API for working with dates and times (JSR 310). I have date and time as string (e.g., "2014-04-08 12:30"). How can I obtain a LocalDateTime instance from the ...
Excide asked 17/3, 2014 at 19:0

11

Solved

Looking for a way to chain optionals so that the first one that is present is returned. If none are present Optional.empty() should be returned. Assuming I have several methods like this: Optiona...
Suffuse asked 14/2, 2015 at 10:32

15

Solved

I would like to implement lazy field initialization (or deferred initialization) without an if statement and taking advantage of lambdas. So, I would like to have the same behavior of the following...
Condescend asked 18/3, 2015 at 21:18

6

Solved

I have installed Ubuntu 20.4 LTS on WSL. My windows 10 already have the JDK installed. Do I need to install JDK on ubuntu on WSL or can I use the Windows 10 JDK in the Ubuntu? How you do Java progr...

9

I'm having an issue with mockito and powermock, I can mock an abstract class with a final static method with no problems. When trying to mock an Interface as with WebIServerSession I'm getting the ...
Farthing asked 8/11, 2018 at 13:48

6

Solved

I'm trying to deserialize an ISO8601 formatted date into Java8 java.time.Instant using Jackson. I registered JavaTimeModule with the ObjectMapper, and turned off the WRITE_DATES_AS_TIMESTAMPS setti...
Fernandina asked 27/3, 2016 at 20:55

9

I want the map to have key as Character and value as Integer, value represents the frequency of the character. The below code won't compile because I am probably using the wrong signature for...
Irresolute asked 19/10, 2023 at 16:36

3

What is the difference between the get() and join() methods of the CompletableFuture<T> class? Below is the my code: List<String> process() { List<String> messages = Arrays.asLi...
Oswaldooswalt asked 3/8, 2017 at 16:51

4

I have below code in one of my methods ZonedDateTime current = Instant.now().atZone(ZoneId.of(AMERICA_NEW_YORK)); I want to mock current in the JUnit test. I tried with java.time.Clock but for...
Nobukonoby asked 21/3, 2019 at 20:58

17

Solved

I'm having a small problem with formatting a Java 8 LocalDateTime in my Spring Boot Application. With 'normal' dates I have no problem, but the LocalDateTime fields are converted to the following: ...
Erastianism asked 29/4, 2015 at 23:8

4

Solved

I recently wrote a small app that periodically checked the content of a directory. After a while, the app crashed because of too many open file handles. After some debugging, I found the error in t...
Sheikdom asked 2/5, 2016 at 19:21

4

This question is not a duplicate of java.lang.NoClassDefFoundError: sun/misc/BASE64Encoder. I am trying to update the Java Version (to 11) in my app and one of the libraries in my app uses sun.mis...
Whoever asked 4/6, 2020 at 11:17

© 2022 - 2024 — McMap. All rights reserved.