Most voted "java-8" questions
Java 8 was released in March 2014 and contains new features, enhancements, and bug fixes to increase the efficiency of Java program development and execution.
Learn more…208 questions
Sort by count of
-
3
votes2
answers247
viewsDoubts regarding the use of the Java 8 stream
I’m practicing some new things that came with Java 8 and between those the use of Stream. I have heard that when we do some action in a list using the stream, it does not change the value of the…
-
3
votes1
answer1289
viewsForeach with Lambda does not work
I have a list of objects I want to go through, but it’s giving error and I’m not understanding why: listaAtendimento.stream().forEach(atendimentoFicha -> {…
-
3
votes1
answer100
viewsClass does not compile when using the new java 8 Feature 'Optional'
Good afternoon I’m using play 2.5.4 with java 8 V01.08.91 And when using some java 8 Features as the 'Optional' class with ifPresent, isPresent or get methods the following error is displayed when…
-
3
votes1
answer403
viewsHow to use Java 8 Stream in an Object[] list
Imagine the following scenario: A list of Object[]. Something like that: List<Object[]> lista = new ArrayList<>(); Object[] dados = new Object[3]; dados[0] = 1; dados[1] = 20; dados[1] =…
-
3
votes1
answer294
viewsHow to convert the String "20190930120000[-3:BRT]" to Localdatetime
I got the following String: "20190930120000[-3:BRT]". I need to convert to LocalDateTime. Does anyone know the mask to be used in DateTimeFormatter.ofPattern("?????")? I’ve come this far:…
-
3
votes1
answer142
viewsLambda expressions in nested classes with multiple methods
I was reading about Ambdas and out of curiosity, I wanted to know why it is not allowed to use when the class/ interface has more than one method, which ends up forcing us to do things like below:…
-
3
votes1
answer991
viewsCalculate age by taking a date of type Date
I’d like to calculate the age by taking the date of birth from the database, through the pojo. I was looking at how to do a date calculation, looking at this question: Calculate age per day, month…
-
3
votes1
answer2002
viewsWhat is Java 8 Optional for? How to use it?
What is the use of Optional Java 8? How to use this feature? The best answers I found on the site were these... What is the difference between the orelse() and orElseGet() methods of…
-
3
votes2
answers295
viewsError in Spring: console Delete request points out that the method is not supported
I am making a request via Ajax to delete a user and get the message that the delete method is not supported, someone has any idea what could be? My controller: package com.br.livraria.controller;…
-
3
votes1
answer62
viewsHow to turn a number reading directly into a stream?
Recently I wrote a reply exploring a little more the API of stream of Java 8, but I must say I was disappointed with some details of my code. The idea was to read a sequence of numbers and then…
-
3
votes1
answer156
viewsmap.foreach Unexpected Return value
I have the following map: private static Map<ParseCreator, Parseable> map = new HashMap<>(); I walk this map as follows: for (Map.Entry<ParseCreator, Parseable> entry :…
-
3
votes2
answers115
viewsSearch information in the database with validation of Hibernate parameters
Analyze the following situation: will come in request the information of the country that can be {0, 1, 2}. The replacement method will look like this: Nomenclature of the country parameter: 0:…
-
3
votes1
answer2872
viewsHow do I verify that a given field/value exists in the JSON document?
{ "timestamp":"2018-10-08T16:58:38.949Z", "dataFrame":"QQ==", "fcnt":15, "freq":902500000, "port":12, "rssi":-69, "snr":10, "sf_used":10, "session_id":"f41e10e8-1c73-499c-8ad7-4cbcd54c8ebd",…
-
3
votes1
answer508
viewsHow to know if there is an element in a List index without error?
I’m trying to give a get() in the indices of a ArrayList, so that if there is something in those positions, I add that value with something else. Only if there is no such index, I would add it.…
-
3
votes1
answer293
viewsScan an Arraylist of objects and check an attribute of an object passed as parameter with an Arraylist
I am a beginner in Java and my teacher passed a list of exercises to practice, in a question I need to create a system that registers a user only if his email has not been registered before. A part…
-
3
votes1
answer54
viewsDifference between changing a variable and a recurring object
I’m recurring in two situations: one changes an object field and the other directly changes the string. What is the difference between these two forms of return since it gives different result?…
-
3
votes1
answer77
viewsHow to express a predicate of equality in Java?
I have the following expression: final String idStatusAutorizada = ...; // valor constante return pendencias.stream() .map(TipoBlocCarga::getIdStatus) .anyMatch(idStatusPendencia ->…
-
3
votes2
answers515
viewsJava 8 stream - performance improvement
I am implemented a method that receives an integer value k (representing the amount of "vacancies") and two lists (p and q) of Integer and perform some operations. Using stream, check which elements…
-
3
votes2
answers200
viewsEliminate consecutive duplicate string letters
How do I scroll through an array of strings and delete consecutive repeat letters? Incoming: String[] x = {"lleonardo", "joaoo"} Exit: String[] x = {"leonardo", "joao"} I created the function below,…
-
2
votes1
answer148
views -
2
votes1
answer315
viewsCollection Map<k,v> Methods
Doubts about the methods replace : compute : computeIfAbsent : computeIfPresent :forEach(briefly all who make use of the function or biFuntion within the input parameter) The replace is it really…
-
2
votes1
answer1930
viewsCalculation of hours with Java 8
I was doing some tests with Java 8, and I was trying to calculate the difference between times of two dates. I did it in three ways, but I don’t know which one would be the right one and I’d like…
-
2
votes1
answer2885
viewsJava 8 - Collecting elements from a list
Good morning. I would like to collect specific elements from a list. I could do the Java 7 style, but I’m curious to know how I would do in the Java 8 style. For example: [[1, 2, 3], [1, 2, 3], [4,…
-
2
votes1
answer173
viewsHow to use Consumer in a variable (Java 8)
I created my own data structure for a Text Adventure game, and in it each Action object has a Consumer. The next step would be whenever someone typed a word, went through the structure and found an…
-
2
votes3
answers4417
viewsJava 8 (Stream) - Grouped sum
Good morning. I have the following function below: private List<Object[]> calcularTotal(List<Object[]> lista, int chave, int valor){ return lista.stream() .map(l -> new Object[]…
-
2
votes2
answers1047
viewsHow to force an html document to always be opened by the browser?
I’m developing a java application for a college job and have a help section for the user where I open a page html in the browser, or at least should open in this. The issue is that if files with…
-
2
votes0
answers244
viewsConvert docx file to pdf without losing formatting?
I am converting a docx to pdf file using the Docx4j API, but I am finding it difficult to maintain the original formatting of the text after performing the conversion. Dependencies: <!-- docx4j…
-
2
votes1
answer630
viewsHow to restrict the values of a date in a field of a java form?
I have a form built with Swing (Java) that has some fields, among them there is one that is the Date of Birth (a String that receives the value of a date and has a formatted field ##/##/####.) which…
-
2
votes2
answers538
viewsException in thread "main" java.lang.Unsupportedoperationexception
Predicate is a functional interface that allows to test objects of a given type. Given a Predicate, the removeIf will remove all elements that return true to that predicate. When trying to use the…
-
2
votes1
answer942
viewsHow to save a localdate to a mysql table?
I have a table book that has a column like "Date" and in my java code I have a field like "localdate". I need to save the data from the "Localdate" field in the table but I’m finding it difficult to…
-
2
votes3
answers514
viewsReturn number of days for the end of the year
How could I make to return the amount of days to the end of the year, counting on today. import java.time.LocalDate; import java.time.Month; import java.time.Period; import…
-
2
votes1
answer1738
viewsFormat a coin-style textfield
I’m using Netbeans, and I can’t show the formatted value as a currency, for example R$1,200.00. When I type in the text field, zeros do not appear. I have a form with two fields: One for name and…
-
2
votes1
answer77
viewsHow to tell whom a class will extend at runtime?
I have the class public class Conhecimento{} This class extends from another class "Cteproc" Only this Cteproc class has "versions" example. V200.Cteproc V300.Cteproc My problem is that in creating…
-
2
votes2
answers2545
viewsMove file list between folders
I have a method that copies files from one folder to another, then deletes the file. It suits me perfectly, but I wonder if there’s any way to do it without having to resort to InputStream and…
-
2
votes1
answer191
viewsTabs Android Stuido
I have a Navigation Drawer working perfectly, but I decided to have a Fragment with 3 Tabs, but giving error, I saw video and I took example, but I can not acetate. //My Navigation Drawer package…
-
2
votes1
answer80
viewsCopy content only from the superclass in java
There is a way to copy only superclass content in another class of the same type through a subclass instance in Java, without accessing getters and setters one by one? Example: public class A {…
-
2
votes2
answers1284
viewsForeach with lambda which returns the sum of iterated items
I’m trying to iterate on a List calling for produtos of objects called Produto, using the forEach, to obtain the sum of the values of these products using the lambda function of the forEach. But I…
-
2
votes1
answer179
viewsFinal local variable in Inner class in Java 8
There was a modification between Java 7 and 8 versions. Where in Java 7 for a local variable to be used within a inner class should be declared final. Now compiling with Java 8, this local variable…
-
2
votes0
answers33
viewsthe type of "OBJECT" is erroneuos
I’m studying competition, and I was trying to make a code using the Semaphore, and that mistake has arisen "the type of Processadorthread(int, Semaphore) is erroneuos" when I tried to run. I’m using…
-
2
votes0
answers119
viewsPrint with Java with IP-configured printer
Well I needed to solve a problem which is, since the software is going to run in the cloud, I was thinking of sending the information to the printer via the IP-configured printer on the machine,…
-
2
votes1
answer86
viewsGenerate String from list contents
I have a class called CoreFiltroSearch that has a list of ICoreFiltro calling for filtros. Follows the class and interface: public class CoreFiltroSearch { private List<ICoreFiltro> filtros =…
-
2
votes1
answer2891
viewsJava 8 - Browse list, change found case, if not, add
In a shopping cart app, I have inside the class CarrinhoCompras the following attribute: List<Item> itens = new ArrayList<>(); And a method to add item, which receives a product, its…
-
2
votes2
answers811
viewsOracle JDK 8 is NOT installed
Good evening, I’m having trouble installing java8 in umbuntu I have tried to delete all apt-get I have installed, and reinstall. I’m following this one…
-
2
votes1
answer23
viewsPUT problems with Spring data JPA
I’m using Controller architecture, DTO, Repositoy, Service Use Postman to test the requests, I can do POST on User normally and when I do GET Postman returns me { "id": 3, "nome": "Arthur", "cpf":…
-
2
votes1
answer258
views -
1
votes1
answer138
views -
1
votes1
answer307
viewsAdd attributes in file creation
I am developing a Java application that creates files in the user directory. So while creating the files I needed to add some attributes in their properties, so that I can identify from where…
-
1
votes1
answer919
viewsHow to limit heap size in a JVM 8?
Until jvm 7 the -Xmx parameter limited the heap size, but today in jvm 8 this is not happening. Today I use the -Xmx200m parameter and my application even consumes 1.5GB in heap, I use a lot of…
-
1
votes1
answer3550
viewsHow to run a java program daily at a given time automatically
Hello, I need to run a program in java daily at a certain time, I found some things about timer.Schedule, but I would like to see some examples, thanks!
-
1
votes1
answer727
viewsList in Textfield or an editable Combobox when user type - Javafx
Someone more experienced, could inform me if Javafx has any way to make a list as you type in the textfield. Example: When you type your facebook email, and you type the first letter and your email…