java-8

Java map an array of Strings to an array of Integers

↘锁芯ラ 提交于 2021-02-07 12:14:33
问题 I found this code on SO to map strings to ints Arrays.stream(myarray).mapToInt(Integer::parseInt).toArray(); But how do I make it map to Integer type not the primitive int? I tried switching from Integer.parseInt to Integer.valueOf , but it seems that the mapToInt() method forces the primitive type. I have an ArrayList of arrays of Integers, so I cannot use primitive ints. 回答1: Since String and Integer are both reference types you can simply call Stream::map to transform your array. Integer[]

Why is hibernate-java8 (hibernate 5.x) jar shown deprecated?

喜夏-厌秋 提交于 2021-02-07 11:59:56
问题 Hibernate 5 and above supports Java8 DateTime Api through jar "hibernate-java8". But the MavenRepository shows a message Deprecated - use hibernate-core instead) alongside the title of the hibernate-java8 jar. Why is the hibernate-java8 jar called deprecated even though it is required to gain the hibernate support for java8? 回答1: You can see the Migration Guide for Hibernate. It specifies that Hibernate 5.2 is built using Java 8 JDK and will require Java 8 JRE at runtime (we are investigating

(Java 8) java.util.function.Supplier

做~自己de王妃 提交于 2021-02-07 11:11:05
问题 In the following code, I tried to call the info method taking a Supplier. (The info method is overloaded: one is taking a String and the other is taking a Supplier.) The compiler complains that "The method info(String) is not applicable for the argument Supplier<Double> ". My expectation is to call the info method taking a Supplier by sending a Supplier object. Can I get some help to understand this error? Supplier<Double> randomSupplier = new Supplier<Double>() { public Double get() { return

(Java 8) java.util.function.Supplier

坚强是说给别人听的谎言 提交于 2021-02-07 11:06:57
问题 In the following code, I tried to call the info method taking a Supplier. (The info method is overloaded: one is taking a String and the other is taking a Supplier.) The compiler complains that "The method info(String) is not applicable for the argument Supplier<Double> ". My expectation is to call the info method taking a Supplier by sending a Supplier object. Can I get some help to understand this error? Supplier<Double> randomSupplier = new Supplier<Double>() { public Double get() { return

(Java 8) java.util.function.Supplier

不羁的心 提交于 2021-02-07 11:05:37
问题 In the following code, I tried to call the info method taking a Supplier. (The info method is overloaded: one is taking a String and the other is taking a Supplier.) The compiler complains that "The method info(String) is not applicable for the argument Supplier<Double> ". My expectation is to call the info method taking a Supplier by sending a Supplier object. Can I get some help to understand this error? Supplier<Double> randomSupplier = new Supplier<Double>() { public Double get() { return

Aggregating more than two properties Java 8

泪湿孤枕 提交于 2021-02-07 10:59:34
问题 To be very simple I have class Per{ int a; long b; double c; String d; } Let say I have 3000 Object of Type Per and collected in a List<Per> pers Now I want to achieve:- Skip if object is null or d is null or blank sum of a sum of b aggregated value of operation performed on c Old way is int totalA = 0; long totalB = 0l; long totalC = 0l; for (Per per : pers) { if (per.d != null && !per.d.trim().equals("")) { totalA += per.a; totalB += per.b; totalC += someOperation(per.c); } } someOperation

Get class name in a static way in Java 8 [duplicate]

匆匆过客 提交于 2021-02-07 10:12:07
问题 This question already has answers here : How to get the name of the calling class in Java? (12 answers) Closed 1 year ago . This is a follow up to more general and similar question/answers In Java 8 I can get class name called the method using new Exception String className = new Exception().getStackTrace()[1].getClassName(); But can I get class name in a static way? edit If I'm inside a different class's method and want to know the class called my method 回答1: Example for getting the class

Get class name in a static way in Java 8 [duplicate]

蹲街弑〆低调 提交于 2021-02-07 10:05:44
问题 This question already has answers here : How to get the name of the calling class in Java? (12 answers) Closed 1 year ago . This is a follow up to more general and similar question/answers In Java 8 I can get class name called the method using new Exception String className = new Exception().getStackTrace()[1].getClassName(); But can I get class name in a static way? edit If I'm inside a different class's method and want to know the class called my method 回答1: Example for getting the class

Java: sorting an array with lambda expression?

て烟熏妆下的殇ゞ 提交于 2021-02-07 09:17:05
问题 I've recently got into functional programming and Java 8 lambdas. I have an array of ints and I want to sort it in an ascending order. The way I am trying to do this with lambda is as follows: Arrays.stream(intArray).sorted((x, y) -> Integer.compare(x, y) == -1); The issue with this is that my compiler says: Error:(12, 32) java: method sorted in interface java.util.stream.IntStream cannot be applied to given types; required: no arguments found: (x,y)->Int[...]== -1 reason: actual and formal

Java: sorting an array with lambda expression?

百般思念 提交于 2021-02-07 09:16:11
问题 I've recently got into functional programming and Java 8 lambdas. I have an array of ints and I want to sort it in an ascending order. The way I am trying to do this with lambda is as follows: Arrays.stream(intArray).sorted((x, y) -> Integer.compare(x, y) == -1); The issue with this is that my compiler says: Error:(12, 32) java: method sorted in interface java.util.stream.IntStream cannot be applied to given types; required: no arguments found: (x,y)->Int[...]== -1 reason: actual and formal