java-8 Questions

10

Solved

What is the easiest/shortest way to convert a Java 8 Stream into an array?
Semaphore asked 15/4, 2014 at 9:0

2

From a simple point of view, lambda expressions are compiled into static methods, since they don’t capture this (i.e. do not access instance members). public class App { public static void foo()...
Hint asked 15/11, 2017 at 17:15

4

I'm trying to use Java 1.8 with lambda expressions with Idea UI Designer, I have in maven: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>ideauidesigner-maven-...
Saturant asked 21/8, 2015 at 7:48

4

Solved

I'm looking for a concise way to filter out items in a List at a particular index. My example input looks like this: List<Double> originalList = Arrays.asList(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6...
Ebarta asked 29/3, 2016 at 20:1

4

Solved

I have POJO definition as follows: class EmployeeDetails{ private String deptName; private Double salary; private Double bonus; ... } Currently, i have lambda expression for Group By 'deptNa...
Firewater asked 23/3, 2017 at 16:39

3

Solved

I have something like this: Integer totalIncome = carDealer.getBrands().stream().mapToInt(brand -> brand.getManufacturer().getIncome()).sum(); Integer totalOutcome = carDealer.getBrands().strea...
Carbonic asked 16/11, 2017 at 18:43

7

Solved

Is there a way in Java's Stream API to map first element of stream differently than other? Equivalent of this code: List<Bar> barList = new ArrayList<>(); for (int i=0; i<fooList....
Overrule asked 23/3, 2018 at 18:13

2

Solved

I'm calling an async client method by streaming over a list of objects. The method returns Future. What's the best way to iterate over the list of Futures returned after the call (so as to process...
Umbles asked 5/4, 2017 at 8:55

3

Solved

I'm implementing some new features of Java 8 on my desktop app and Hibernate 3.6 seems to doesn't like it. I added to an Interface a "default method", since then Hibernate it throwing: 2014-10-02...
Trichomoniasis asked 2/10, 2014 at 17:32

10

Solved

How can I get the last element of a stream or list in the following code? Where data.careas is a List<CArea>: CArea first = data.careas.stream() .filter(c -> c.bbox.orientationHorizonta...
Clerc asked 29/1, 2014 at 9:25

16

Solved

In Java 8, methods can be created as Lambda expressions and can be passed by reference (with a little work under the hood). There are plenty of examples online with lambdas being created and used w...
Kenleigh asked 28/11, 2012 at 12:6

2

Solved

Which one is better in terms of performance? finalWords.stream().forEach(word -> stringBuilder.append(word).append(”,“)); String finalResult = stringBuilder.toString(); VS String finalRes...
Mouser asked 4/5, 2018 at 14:32

4

Solved

I want to sort String elements in the array months by length using Arrays.sort method. I was told here, that it's possible to use lambda expressions instead of creating new class implementing Compa...
Filide asked 23/2, 2014 at 16:7

3

final List<Toy> toys = Arrays.asList("new Toy(1)", "new Toy(2)"); final List<Item> itemList = toys.stream() .map(toy -> { return Item.from(toy); //Creates Item type }).collect(C...
Freespoken asked 22/5, 2017 at 12:56

4

Solved

Say I have a list of Lists.. List<List<String>> lists = new ArrayList<>(); Is there a clever lambda way to collapse this into a List of all the contents ?
Anemoscope asked 19/9, 2014 at 19:57

14

Solved

In Java 8, you can use a method reference to filter a stream, for example: Stream<String> s = ...; long emptyStrings = s.filter(String::isEmpty).count(); Is there a way to create a method ...
Indeterminism asked 31/1, 2014 at 19:4

2

Solved

I have little maven project that uses com.sun.istack.internal.Nullable. I tried both JDK 9 and 1.8, and still get error about package does not exists. I search for the package and find some: https:...
Dysphoria asked 13/12, 2017 at 12:39

2

Solved

Since the introduction of Java 8, is Hibernate waiting some changes? specially Is there any way to write queries with lambdas in Hibernate? (i.e. like a .net Linq-to-SQL style) If not, when it's...
Montpellier asked 3/7, 2014 at 20:41

2

Solved

I am trying to use @CreationTimestamp and @UpdateTimestamp with LocalDateTime type, but it is giving me org.hibernate.HibernateException: Unsupported property type for generator annotation @Creatio...
Dunfermline asked 6/11, 2018 at 12:13

4

Solved

What is the Java 8 functional interface for a method that takes nothing and returns nothing? I.e., the equivalent to the C# parameterless Action with void return type?
Palaeozoology asked 26/5, 2014 at 11:8

8

Solved

In Java 8, this works: Stream<Class> stream = Stream.of(ArrayList.class); HashMap<Class, List<Class>> map = (HashMap)stream.collect(Collectors.groupingBy(Class::getSuperclass)); ...
Raised asked 25/3, 2014 at 3:45

6

I have JSONs with a date-time attribute in the format "2014-03-10T18:46:40.000Z", which I want to deserialize into a java.time.LocalDateTime field using Gson. When I tried to deserialize, I get th...
Drupe asked 10/3, 2014 at 20:3

11

Solved

In my test case, I need test time sensitive method, in that method we're using java 8 class LocalDate, it is not Joda. What can I do to change time, when I'm running test
Adrianople asked 25/9, 2015 at 23:26

13

Solved

I have noted that many Java 8 methods in Oracle JDK use Objects.requireNonNull(), which internally throws NullPointerException if the given object (argument) is null. public static <T> T req...
Yoakum asked 11/8, 2017 at 10:26

4

Solved

I'm trying to apply my knowledge of streams to some leetcode algorithm questions. Here is a general summary of the question: Given a string which contains only lowercase letters, remove duplicate ...
Allocate asked 22/8, 2020 at 3:18

© 2022 - 2024 — McMap. All rights reserved.