Questions tagged [java-8]

Use this tag for questions specific to Java 8 which is version 8 (internal number 1.8) of the Java platform, released on 18 March 2014. In most cases you should also specify the java tag.

2
votes
0answers
15 views

Java 8 - throw multiple generic checked exceptions in lambda

In a project I am working at, I have found a class which wraps all methods of its super-class in some elaborate exception handling. It looks similar to that: public void method1() throws ExceptionA { ...
0
votes
3answers
46 views

Iterate through elements of List - Java 8

I have a List of String, i need to iterate elements and create a new Object for each element in the list and add to a parent list, how do ido in Java 8 , this is what i tried so far: List<...
0
votes
0answers
4 views

calling fallback method automatically for all HystrixCommands in group

I have 3 Hystrix commands called in order A, B, C. if call to A fails, and response is returned from fallback method,then how can i make hystrix call fallback methods of B and C as well. One ...
4
votes
3answers
53 views

Elegant way to flatMap Set of Sets inside groupingBy

So I have a piece of code where I'm iterating over a list of data. Each one is a ReportData that contains a case with a Long caseId and one Ruling. Each Ruling has one or more Payment. I want to have ...
0
votes
0answers
14 views

Could not initialize class org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil$ClassLoaderHolder

I try to install and run OpenTSDB in accordance to the official documentation. When I run command from here: tsdtmp=${TMPDIR-'/tmp'}/tsd # For best performance, make sure mkdir -p "$tsdtmp" ...
2
votes
1answer
28 views

Java functional interfaces : how to wrap a function with andThen or similar

I have some repetitve code that goes : router.post("/fleets/:fleetid/vehicles/:boxid/ping").handler(ctx -> pingBox(pingBoxTimer, oemUrl, ctx)); router.post("/fleets/:fleetid/...
0
votes
0answers
27 views

JavaFX CSS is not working when using fx:factory to populate custom GridPane component

I have a problem with CSS on Component when fx:factory is used, additionaly gridLinesVisible property does not seem to work either. Let me get to the point, my component looks like this: <?import ...
0
votes
1answer
44 views

How do I read and accept custom CLI arguments with name/id/title in Java? [on hold]

I want to read and accept Custom CLI arguments values when I run my Java program as shown below: java BookSales --books=/path/to/books.list --sales=/path/to/sales.list --top_selling_books=3 --...
0
votes
2answers
36 views

Adding to a list using Java stream within the filter method

Map<Integer, Boolean> map1= new HashMap<>(); map1.put(1, true); map1.put(2, true); map1.put(3, false); map1.put(4, true); map1.put(5, false); Map<Integer, ...
0
votes
1answer
26 views

ClassLoader does not find resource files following build

I have been running into issues trying to direct the Java ClassLoader to retrieve JSON files from the test/resources directory following deployment. public class TestFileUtil { private static ...
-2
votes
3answers
44 views

Convert Unix time stamp to Date [duplicate]

I have Long value 1282680754000 where if I check this value in https://www.epochconverter.com/ it gives me Tuesday, August 24, 2010 8:12:34 PM But if I use new DateTime(1282680754000).toDate() I get ...
0
votes
3answers
47 views

Concatenates numbers in Java 8 for the Single quotes and commas

I am new to Java 8 and looking to implement below in Java 8 only. I have the following numbers 1111 2222 3333 4444 I want to convert all these numbers like '1111','2222','3333','4444' The list of ...
0
votes
1answer
18 views

How to make streaming sql in spring jdbc template??

We have a sql in spring jdbc template fetching millions of records, which we want to process in Java.. Any way to do the same using less memory?
-1
votes
0answers
34 views

Streaming for iterating maps and getting multiple counts [on hold]

I have the below code in Java 8 which I would like to convert to lambda stream based. int manager = 0; int reportee = 0; int contractor = 0; int totalProjects = 0; final Map<String, List<...
3
votes
1answer
61 views

Why I'm getting Stream<Object> when I call stream() after collect()?

Consider the following example, which is not compiled: List<Integer> list = Arrays.asList(1, 2, -3, 8); list.stream() .filter(x -> x > 0) .collect(...
-3
votes
1answer
31 views

Using lambdas to extract an Object attribute contained in an ArrayList [duplicate]

I have made a class called User with two string attributes: Login and Password. I have a database (userList, of type ArrayList<User>) with all the existing users, and I want to know if a login ...
0
votes
1answer
9 views

IntelliJ Jar Error : Invalid signature file digest for Manifest main attributes

I'm using IntelliJ IDE on an armx64 linux-based system, where i'm working on a non-maven java project that have a lot of modules (dependencies) linked to it. When running my project from the IDE ...
5
votes
4answers
109 views

How to check if an ArrayList of Strings contains substrings of another ArrayList of Strings?

List<String> actualList = Arrays.asList ("mother has chocolate", "father has dog"); List<String> expectedList = Arrays.asList ("mother", "father", "son", "daughter"); Is there a way to ...
0
votes
2answers
56 views

Call default method from other interface in another default method

This code crashes: public class MyClass { public static void main(String args[]) { Person person = new Person(); person.selectMe(); } } class Entity {} interface EntityNameable&...
0
votes
0answers
62 views

Java Lambda - losing type [on hold]

I'm iterating over a List of elements with generic type like a following: String orderItems = order.getOrderItems().stream() .filter(orderItem -> orderItem.getOrderComment() != ...
-4
votes
3answers
80 views

Java8 lambda expression for sorting

In order to sort a collection can use following : import java.util.ArrayList; import java.util.Collections; public class LambdaSort { public static void main(String args[]) { ArrayList ...
-6
votes
2answers
58 views

Using Java 8 how to access and set class properties directly without getters and setters? [on hold]

Assume I have below Java class: class Foo { public String bar; } How can I set and access bar directly like: Foo foo = new Foo(); foo.bar = "Hello"; System.out.println(foo.bar); There are ...
1
vote
3answers
73 views

Method Reference for Integer type List

I have code like below. List<Integer> parameters = ... String string = " NOT IN (" + parameters.stream() .map(parameter -> parameter.toString()) .collect(...
13
votes
3answers
734 views

What are practical uses of the java.util.function.Function.identity method?

Why should I use Function.identity() when it returns the same thing which it receives without doing anything using the input or modifying the input in some way? Apple apple = new Apple(10, "green"); ...
0
votes
0answers
15 views

how to mock private instance variable groovy

I have following code public class Employee{ private List<String> employeeDetails=new ArrayList<>(); @Autowired private EmployeeEntity employeeEntity;// this is an interface public ...
4
votes
2answers
52 views

Java stream map modifies custom class object not built in classes

class Employee { public String name; public Integer age; public Employee(String n, int age) { this.name = n; this.age = age; } public String toString() { ...
2
votes
1answer
42 views

Why does Oracle still ship Java 8 for the non-developer desktop JRE?

With the advent of Java 11, the common consumer JRE is 3 whole feature releases behind. Would it not make sense to update by now, or does Oracle just intend for developers to set their source ...
0
votes
1answer
31 views

Groovy ConcurrentHashMap forEach call

groovy 2.4.7 I'm trying to iterate ConcurrentHashMap in groovy, trying the call forEach(long parallelismThreshold, BiConsumer action) def Map wrapperMap = processFileContents(fileContents) //...
1
vote
0answers
26 views

cache2k and Generic T do not play nice together

In the cache2k User Guide, §2.3. Cache Aside has a code sample and sentence about cache-aside. Cache<String, String> routeToAirline = new Cache2kBuilder<String, String>() {} .name("...
-2
votes
1answer
71 views

List of String to Map Java8

I have a list of String in my application. Every String is actually an output of 2 different strings concatenated by ".". e.g. Stack.Overflow Now, I am trying to convert this list to a Map with key ...
-1
votes
1answer
33 views

How to find median value by using java stream API [duplicate]

How to find median value by using java stream API : For example I have the following array int []arr ={0,1,2,4,6,5,3}; Is there a way and what is the best way to find the median value using java ...
-2
votes
4answers
72 views

How to convert LocalDateTime to `“yyyy-MM-dd'T'HH:mm:ss'Z'”` format

I'm trying to parse the String in format "yyyy-MM-dd'T'HH:mm:ss'Z'" into LocalDateTime and if day is sunday or saturday i want to change date to monday and return in same format, i know i can add days ...
1
vote
1answer
20 views

Differences of implementations from IBM and Oracle of java BigDecimal in java 8?

Can anybody explain me the differences of implementations from IBM and Oracle of java BigDecimal, in java 8? I know that the IBM implementation of BigDecimal (com.ibm.math.BigDecimal) is deprecated ...
1
vote
2answers
27 views

Collect groupBy on deep property

private Map<String, Set<Square>> populateZuloSquare(List<Square> squares) { if (squares == null || squares.isEmpty()) { return emptyMap(); } Map<String, Set&...
2
votes
1answer
35 views

Find first over several streams of different collection Types

public class ImmutableCrazySquares { private final List<Square> xraySquare; private final Map<String, Set<Square>> yankeSquare private final Map<String, Set<Square>...
5
votes
4answers
76 views

Maximum of list with expensive custom key function

In Java to find the maximum element of a sequence you write: GameState bestGs = Collections.max(ns, Comparator.comparing(e -> minimax(e))); Here minimax is a function returning a number ...
1
vote
0answers
22 views

JavaFX + ProcessBuilder / Runtime.exec() starts process after JVM closes [duplicate]

I'm experiencing a very weird behavior from JavaFX. It is related to Why are Runtime.getRuntime().exec and ProcessBuilder starting my second jar application after the first one exits? that wasn't ...
1
vote
1answer
26 views

Deserialize byte array into class whose name is given as String

I have data that is serialized from a java object(there can be different types of objects), I also have the fully qualified class name of the type of the serialized data in String format. Now I want a ...
-4
votes
1answer
47 views

Integration test cases not working after jdk10 upgrade

Getting the below error while running functional test cases after upgrading to jdk10. Could not target platform: 'Java SE 10' using tool chain: 'JDK 8 (1.8)'. build.gradle import com.bmuschko....
2
votes
1answer
106 views

NPE in Java HashSet.isEmpty()

I got an NPE in java.util.HashSet.isEmpty() on line 191. I guess, this line just calls isEmpty() on the internal map field. To my surprise, this field is transient, so after deserialization, it ...
0
votes
0answers
13 views

IllegalArgumentException: UT010011 when starting wildfly 14 with struts 2.3, java 8

I am trying to deploy my application using wildfly 14 and struts 2.3 , but while starting wildfly I am getting the following exception 12:11:05,540 ERROR [org.jboss.msc.service.fail] (MSC service ...
0
votes
1answer
66 views

Loop multiple different type of lists and create another using java 8 lambda expressions

I am writing a code to loop through multiple different type of lists and create another based on some business validations using java 8 lambda expressions. Business Validation/Logic: there are 2 ...
2
votes
1answer
62 views

Convert List<T> to Map<T, U> using Java 8

I'm trying to convert a List<T> to Map<T, U> using Java 8 but I keep getting stuck at this one part. What I am trying to have is the value of the map to be of some variable of type U. Lets ...
0
votes
1answer
29 views

sql query behaving differently for different jdk version

I have a oracle sql date query which works fine for java 7, but when the same query is run for java 8 it is throwing an error as: "not a month". If I use the query such as: DATA_RECEIVED_MOMENT > ...
0
votes
0answers
14 views

To verify a JWT token with RSA

I am trying to verify a jwt token and getting the exception: Exception in thread "main" java.lang.IllegalArgumentException: Only private key data is currently supported Any pointers on how to ...
3
votes
3answers
79 views

Java 8 sort using a specific range

I have a Distance object which have a totalDistance attribute. Using java 8 steams I need to sort a List by the totalDistance. I know that I could sort this list by using something like: .sorted(...
0
votes
2answers
65 views

how to find the max value of nested arraylist of string using streams

I have an ArrayList in the below format List<List<String>> ll = [["0", "a"], ["1", "b"], ["0", "c"], ["1", "d"]] I want to find the maximum value by considering the first position in the ...
0
votes
2answers
72 views

How to loop through multiple Lists and create another list with merging of unique values from both the lists using Java 8 lambda expressions

I am writing a code to loop through multiple Lists and create another list with merging of unique values from both the lists using Java 8 lambda expressions. Model class: class ServiceMap{ ...
0
votes
1answer
68 views

Java 8 efficient way for adding object to list

Is there a short and efficient way to add object to a list with null check? Book book = new Book(); if (CollectionUtils.isNotEmpty(library.getBooks())) { library.getBooks().add(book); } else {...
2
votes
1answer
64 views

If without converting the lines to string does the code work fine?

If without converting the below lines to string can it work fine? Do I need to use the Stream <String> in front of the lines = Files.lines(Paths.get("c:\\demo.txt")); to convert the file lines ...