java-8

descendingIterator for java.util.List

五迷三道 提交于 2020-04-10 03:37:10
问题 LinkedList can be iterated using ascending or descending iterator like this: LinkedList<Object> list = new LinkedList<Object>(); ... StringJoiner sJ1 = new StringJoiner(" "); list.iterator().forEachRemaining(a -> sJ1.add(a.toString())); System.out.println("averse: \n" + sJ1.toString()); StringJoiner sJ2 = new StringJoiner(" "); list.descendingIterator().forEachRemaining(a -> sJ2.add(a.toString())); System.out.println("reverse: \n" + sJ2.toString()); averse: Hello 2 Chocolate 10 reverse: 10

What is temporal object in Java?

北城以北 提交于 2020-04-08 05:46:26
问题 I was exploring TemporalQuery and TemporalAccessor introduced in Java 8. TemporalAccessor seems to be specially designed for temporal objects such as date, time, offset or some combination of these . What are temporal objects? Some googling gave its meaning as An object that changes over time But not able to relate this in the context of Java? 回答1: According to with Joda-Time & JSR 310, Problems, Concepts and Approaches [PDF], the TemporalAccessor : Defines read-only access to a temporal

Is there a way to coalesce repeated numbers in a list using streams in Java 8?

人盡茶涼 提交于 2020-04-07 19:10:41
问题 e.g.#1 [1, 1, 1, 2, 22, 35, 35, 120, 320] ==>> [3, 2, 22, 70, 120, 320] note how repeated consecutive 1's and 35's are coalesced to 3 and 70 respectively e.g.#2 [1,1,3,1,1] ==>> [2,3,2] 回答1: Stream.of(1, 1, 1, 2, 22, 35, 35, 120, 320) .collect(Collectors.toMap( Function.identity(), Function.identity(), Integer::sum, LinkedHashMap::new )) .values() .forEach(System.out::println); In the case the you posted a comment, you would need a custom collector, actually: static class Custom implements

Is there a way to coalesce repeated numbers in a list using streams in Java 8?

跟風遠走 提交于 2020-04-07 19:09:34
问题 e.g.#1 [1, 1, 1, 2, 22, 35, 35, 120, 320] ==>> [3, 2, 22, 70, 120, 320] note how repeated consecutive 1's and 35's are coalesced to 3 and 70 respectively e.g.#2 [1,1,3,1,1] ==>> [2,3,2] 回答1: Stream.of(1, 1, 1, 2, 22, 35, 35, 120, 320) .collect(Collectors.toMap( Function.identity(), Function.identity(), Integer::sum, LinkedHashMap::new )) .values() .forEach(System.out::println); In the case the you posted a comment, you would need a custom collector, actually: static class Custom implements

How to install openjdk-8-jdk on Debian 10 (Buster)?

耗尽温柔 提交于 2020-04-07 17:10:15
问题 It seems Debian does not support openjdk-8-jdk anymore due to a security issue. What is the easiest way to install openjdk-8-jdk for Debian 10 (Buster)? 回答1: alternatively, you can use adoptopenjdk repository. wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add - sudo add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/ sudo apt-get update && sudo apt-get install adoptopenjdk-8-hotspot https://adoptopenjdk.net/installation.html 回答2:

oracle.jdbc.OracleDatabaseException: ORA-00972: identifier is too long

℡╲_俬逩灬. 提交于 2020-04-06 22:26:33
问题 Here is my Entity class @Entity public class ProjectDetails { @Id private int projectId; private String projectDescription; private int languageId; } @Entity public class Project { @Id private int projectId; private String projectName; private LocalDate projectStartDate; private LocalDate projectEndDate; private String projectStatus; @OneToOne private ProjectDetails projectDetails; } I have a JPA method like this List<Projects> findProjectsByProjectsIdAndProjectDetailsLanguageId(int projectId

oracle.jdbc.OracleDatabaseException: ORA-00972: identifier is too long

大憨熊 提交于 2020-04-06 22:26:30
问题 Here is my Entity class @Entity public class ProjectDetails { @Id private int projectId; private String projectDescription; private int languageId; } @Entity public class Project { @Id private int projectId; private String projectName; private LocalDate projectStartDate; private LocalDate projectEndDate; private String projectStatus; @OneToOne private ProjectDetails projectDetails; } I have a JPA method like this List<Projects> findProjectsByProjectsIdAndProjectDetailsLanguageId(int projectId

Why is Streams.allMatch(in Java8) trying to evaluate all the expressions even if the value can be determined midway?

折月煮酒 提交于 2020-04-06 18:43:12
问题 Consider this snippet - String a = "hello" , b = null, c = "guru"; boolean value = Stream .of(a, b, b.substring(2),c) .allMatch(x -> x != null); System.out.println(value); This results in NPE. It seems to be doing b.substring(2) and since b is null , NPE is thrown. Why is this condition evaluated? The second expression b is null and hence evaluates to false . So, allMatch will be false regardless of the truth values of the subsequent operations. In that case, why is it trying to evaluate b

Why is Streams.allMatch(in Java8) trying to evaluate all the expressions even if the value can be determined midway?

孤街浪徒 提交于 2020-04-06 18:42:58
问题 Consider this snippet - String a = "hello" , b = null, c = "guru"; boolean value = Stream .of(a, b, b.substring(2),c) .allMatch(x -> x != null); System.out.println(value); This results in NPE. It seems to be doing b.substring(2) and since b is null , NPE is thrown. Why is this condition evaluated? The second expression b is null and hence evaluates to false . So, allMatch will be false regardless of the truth values of the subsequent operations. In that case, why is it trying to evaluate b

Retrieving list of employees with lowest salary using stream [duplicate]

余生颓废 提交于 2020-04-05 16:04:32
问题 This question already has answers here : How to force max to return ALL maximum values in a Java Stream? (5 answers) Closed 7 months ago . I'm trying to retrieve a list of those with lowest salary from a list of employees. So far I've managed to find the employee with lowest salary, but I want to retrieve multiple if several employees have the same salary. I think the solution is supposed to be in one line. So I can't create a variable with the lowest salary and just check each one for