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.

0
votes
2answers
41 views

Transforming a List<Object> into a Map<key, List<Object>> using an object's attribute as key

I have an object Foo with the following elements: class Foo { int id; int departmentId; boolean condition1; boolean condition2; boolean condition3; //... } and a list of Foo ...
-1
votes
1answer
29 views

Using nested for loops in Java 8, to find out given difference [duplicate]

I have below code where I am using nested for loops and I have some condition that breaks the inner for loop, and this improves the performance of this code. Assume that the list provided is already ...
0
votes
3answers
64 views

Using nested for loops in Java 8

I have below code where I am using nested for loops and I have some condition that breaks the inner for loop, and this improves the performance of this code. public static int getMaxValue(List<...
1
vote
1answer
45 views

How to split a stream into multiple stream based on certain criteria?

I have a list of integers and I want to return sub lists of integers from this list using java 8 streams where my sub list contain all the positive integers from original list just before it ...
-1
votes
0answers
23 views

What is advantage of using Functional Interface over Regular Interface? [duplicate]

I am trying to understand advantage of using functional interface over regular interface. So, let's say I have this code package Java8; public class FunctionalCheck implements InterfaceOne{ ...
0
votes
0answers
12 views

How to validate the separator / delimiter using an OpenCSV library?

Based on the library OpenCVS I wrote in the following code: @Override public List<String[]> parseFile() throws IOException, InvalidArgumentException { FileReader fileReader = new ...
7
votes
0answers
89 views

JVM's heap size keeps increasing (but usedMemory() keeps decreasing)

I have a single Java application running on eJDK 1.8.201. I observed that the system reported RSS usage of the java process keeps increasing, it will reach over than 90% of the physical memory that is ...
0
votes
0answers
16 views

How to install java-8 using configure file

I'm installing java-8 on windows-7 using Installing With a Configuration File.But,i have some issues on while installing java setup execute in command prompt. I have my java-8 .exe file, i want to ...
0
votes
1answer
30 views

spring webflux webclient response convert list of string to string

Response: [ { "version": "1.0", "content": [ "12345", "67076", "123462", "604340", "1331999", "1332608", "1785581", ] } ] Code: Mono<List<String>> ...
0
votes
1answer
41 views

Java CompletableFuture - main class not terminated

I am trying to implment CompletableFuture which invokes a dummy callback method when completed. However, after adding CompletableFuture.get() method my main class doesn't terminate. I tried ...
0
votes
2answers
40 views

Java8 time library does not interpret BST timezone correctly

This is not the dup of another timezone question because I do not have the luxury to choose the timezone format. I am in the process of migrating my java code to use the new java8 time library, but I ...
4
votes
3answers
67 views

Using Streams filter Map based on a list of keys

I have a particular problem and was wondering whether the Java 8 Streams API could solve it. I know that this can be done outside of using Streams API but I don't want to add all the boilerplate code ...
0
votes
0answers
14 views

Struggling to enable SSLv2Hello in Apache CXF, Java 8, No Spring

This is going to seem backwards, but I'm developing a web server specifically to interface with a third party client. This third party client only supports SSLv3, TLSv1.0, or TLSv1.1. I'm also ...
5
votes
2answers
66 views

Using Java 8 Streams' Collectors to increment value based of existing key/value pair

Suppose there is a List<Object> and that Object contains two methods: getUserId and getPoints. Consider that List<Object> contains three objects, and they contain the following data: ...
6
votes
4answers
98 views

Java Comparator with null fields

I have a list of entities Entity with the fields id and createdDate. I want to sort them as following: higher id first if id null, most recent createdDate first I've tried the following ...
0
votes
2answers
116 views

Streams in Java are much slower than native for loop - why? [duplicate]

To my understanding streams are faster than conventional old programing. However, when I ran following code the result is something I did not expect. public class Application { public static ...
1
vote
3answers
48 views

Convert epoch time in UTC to epoch time in another Timezone [on hold]

I need to convert epoch time in UTC to epoch time in different timezone. Example : 1389556017000 in UTC to epoch time in America/Tijuana timezone. public static void main(String[] args) { ...
-1
votes
1answer
53 views

Java Streams and Composite object [duplicate]

I have a java collection which contains a table of data, I need to filter the data based on the combination of fields. VRNT_CD ITM_NB COMMT_TEXT 10 A0A SampleText1 10 A0A ...
-6
votes
0answers
36 views

Re arranging of an number to get the highest number [on hold]

rogram for Given a number, which can be either positive or negative and can have a fractional part, return a number that has a maximum value in java. example: input 235 output 532 input 456.231 ...
0
votes
1answer
15 views

Timezone Springboot Tomcat 8 AS

On my spring boot app running on Tomcat 8 i have this code into SpringBootServletInitializer: public class MyApplication extends SpringBootServletInitializer { @Override protected ...
5
votes
1answer
44 views

How to use Comparator.comparing() to compare string as double?

I have a List of Accounts and I am trying to use Comparator.comparing to sort them. However, since the balance is string not double, it is sorting incorrectly. Is there a way to sort the balance field ...
-3
votes
0answers
36 views

How to know if a piece of code in a parallel stream is still running

I need to make a thread wait for other thread in a parallel stream to finish before executing the next block of code parallelStream().forEach( e-> { //run block of code //if done ...
0
votes
0answers
32 views

Requirements check failed for JDK 8

I have installed JDK 8 on my Cordova prodejct. When i run the yum install java-1.8.0-openjdk, i get this: Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: ...
-4
votes
1answer
44 views

how to write a clean code without using enums

I have an enum as below public enum ProductType{ P1("Pone") P2("Ptwo") public String value; public String getValue(){ return value; } public Product fromValue(Brand b){ if(b....
0
votes
0answers
32 views

Clean code applying weights to Guava Table values

I am transforming guava Table object, applying weights. method input Type is below, where Row and Column are some classes. columnWeightsPerRow : Table<Row, Column, Double> weightsPerRow ...
0
votes
0answers
35 views

How to aggregate two HashMap<String, String> using KStream methods?

I receive a messages from a Kafka. I get two messages with the same ID and try to aggregated into one. It's work, but I received only one message KStream<String, byte[]> stream = ...
3
votes
1answer
33 views

Calendar.DAY_OF_WEEK_IN_MONTH equivalent in ZonedDateTime in java8

I am trying to check Thanksgiving (4th Thursday of November). I have ZonedDateTime as 2019-11-23T08:43:14.699-07:00[America/Los_Angeles] How do I check whether it is4th Thursday or not using java 8 ...
4
votes
3answers
59 views

Local variable i defined in an enclosing scope must be final or effectively final

I want to implement this endpoint with internal search: @PostMapping("terminals_risk_filter/change_order/{terminalId}") public ResponseEntity<?> updateFiltersPositions(@PathVariable Integer ...
24
votes
6answers
1k views

How to remove multiple elements from Set/Map AND knowing which ones were removed?

I have a method that has to remove any element listed in a (small) Set<K> keysToRemove from some (potentially large) Map<K,V> from. But removeAll() doesn't do, as I need to return all keys ...
0
votes
0answers
32 views

Java AWS Lambda json input not converted to object

I'm trying out the Java Lambda example, but the input json is not converted to the Java class and all the inputs are shown as null. Instead the input json is present inside a body tag and is getting ...
1
vote
1answer
48 views

Why Pipeline grouping using Java's stream API collectors taking more time?

I'm creating a Map of Map from a list using Stream API. List contains 10 million records. I have done this with single statement using two 'groupingBy' operations as below. The problem is that this ...
3
votes
4answers
50 views

How can I use an object from a lambda expression in a different lambda expression

I have this code service.confirm(identity, id) .map(confirmationResponse -> InternalToExternalResponse.mapToExternal(confirmationResponse)) .map(externalResponse-&...
0
votes
0answers
28 views

Java8 - Asynchronous execution of independent code

Java8 - In my portal, on the page (Homepage) which gets displayed after Customer logs in, I need to display multiple sections like, Order details, Available invoices, Catalog pdf etc. There is no ...
4
votes
3answers
58 views

Note able to get Distinct int[] from List<int[]>

I am trying to get distinct List with unique int[], but I am still getting duplicates. List<Integer> set1 = Arrays.asList(2, 3, 4, 5, 10, 4, 5, 6, 4); List<Integer> count = new ArrayList&...
1
vote
2answers
32 views

findAny from nested List using Java Streams

I need to find some object from nested List. I believe the class code is not needed, because the filtering is exposed in nested For-Each Loop. int value = someValue; MyObject found = null; for (...
1
vote
5answers
95 views

Compare Array List with Linked List by adding element into linked list using Java 8

I am comparing the ArrayList and LinkedList. For eg: ArrayList => {2,4,5} LinkedList => 1->3->8->7->6 Final Output => 1->2->3->4->5->8->7->6 I need ...
10
votes
1answer
126 views

Different deserialization behavior between Java 8 and Java 11

I have a problem with deserialization in Java 11 that results in a HashMap with a key that can't be found. I would appreciate if anyone with more knowledge about the issue could say if my proposed ...
0
votes
1answer
38 views

Operations on properties in Java Class

I have a class: class Test{ private int a; private int b; //setters, getters } I create 2 instances of type Test. They are initialized and fields are populated via 2 sources (say a file and ...
-1
votes
0answers
23 views

How to provide line break or new line for String in XML

I am trying to read the String defined inside the XML file and printing that into a log through java. The String contains multiple line but XML is taking it as a single line. I have tried with \n but ...
2
votes
3answers
82 views

Getting the max occurences of each individual number from a HashMap<Integer, List<Integer>>

I've been dealing with an exercise, in which I have to find a solution for the following problem: I have a HashMap<Integer, List<Integer>> and I have to get a List containing each of ...
0
votes
0answers
54 views

Lambda functions back to anonymous classes

I am backporting an android application made for Android 9 back to work with android 5.1 and there are a lot of problems, among them there is the fact that Java 8 is not supported. Lambdas and method ...
1
vote
2answers
37 views

What is the most portable way to open the default Java truststore?

I am programmatically manipulating the default Java TrustStore. In order to do that, I need its path. I tried reading javax.net.ssl.keyStore and javax.net.ssl.trustStore and they're both undefined. ...
0
votes
0answers
32 views

How to fix: “/bin/bash: jar: command not found” error in Java JDK 8 manual install?

Due to dependency of another software I'm going to build, I had to install Java JDK 8 manually, I used the following guide: https://www.vultr.com/docs/how-to-manually-install-java-8-on-ubuntu-16-04 ...
5
votes
3answers
79 views

Collectors.toMap write a merge function on a property of object which is not used a value

I am creating a Map<String,String> from List<Person> using java-8 stream persons.stream() .collect(Collectors.toMap(Person::getNationality, Person::getName, (name1, name2) -> ...
1
vote
1answer
66 views

Cannot resolve constructor in Java 8

I want to create a cloned list. I am using the below code snippet, but my IDE is showing a compilation error as "Cannot resolve constructor" even though MyClass has a default constructor. List<...
0
votes
1answer
39 views

how can I delete a portion of a linked list?

let's say my list is: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> 10 I want to delete a portion of this list. e.g. from index 1 to index 5. so the list would change to: 1 -> 7 -> 8 -> 9 -> 10 i'm ...
-3
votes
2answers
90 views

change a value from the List using java8

I want a value get nullified before sending to UI. public class MedicalInfoVO { private Integer medicalDeoId; private List<MedicalCoverageVO> medicalCoverages; private List<...
0
votes
1answer
21 views

Log4j: Setting the generated log filename to include hostname

I am trying to generate logs using log4j. Logging part is working correctly, but I want to include the hostname (where the logs are generated) to be appended in the filename. for eg: my current ...
0
votes
0answers
23 views

How to give multiple target files in hive runner for unit test

For example: @HiveSQL(files = {"serdeTest/create_table.sql","serdeTest/hql_custom_serde.sql"}, autoStart = false) public HiveShell hiveShell; If i have a source and target file for doing the ...
0
votes
1answer
49 views

CompletableFuture and exceptionally - what is missing here?

As I try to understand the exceptionally functionality, I read several blogs and posts , but I don't understand what is wrong with this code: public CompletableFuture<String> divideByZero(){ ...