java-8

Get Index while iterating list with stream [duplicate]

柔情痞子 提交于 2020-07-18 04:28:19
问题 This question already has answers here : Is there a concise way to iterate over a stream with indices in Java 8? (22 answers) Closed 2 years ago . List<Rate> rateList = guestList.stream() .map(guest -> buildRate(ageRate, guestRate, guest)) .collect(Collectors.toList()); class Rate { protected int index; protected AgeRate ageRate; protected GuestRate guestRate; protected int age; } In the above code, is it possible to pass index of guestList inside buildRate method. I need to pass index also

Static Method in Interface with Generic signature

笑着哭i 提交于 2020-07-17 10:20:16
问题 As of Java 8 you can have default or static methods implemented in Interfaces as the below public interface DbValuesEnumIface<ID, T extends Enum<T>> { T fromId(ID id); ID getId(); static String getDescriptionKey(){ return "this is a test"; } } I would like to declare the above with the static method having a signature that uses bounds defined by the implementing classes since the method's implementation should be the same for all,with the only thing different should be the generics declared,

summaryStatistics Method of IntSummaryStatistics

╄→гoц情女王★ 提交于 2020-07-16 06:41:43
问题 Why summaryStatistics() method on an empty IntStream returns max and min value of integer as the maximum and minimum int value present in the stream? IntStream intStream = IntStream.of(); IntSummaryStatistics stat = intStream.summaryStatistics(); System.out.println(stat); Output : IntSummaryStatistics{count=0, sum=0, min=2147483647, average=0.000000, max=-2147483648} What is the point of returning these values? Should not it considered the wrong result? 回答1: See IntSummaryStatistics.getMax()

Java 8 DateTimeFormatter for month in all CAPS not working [duplicate]

萝らか妹 提交于 2020-07-15 06:55:30
问题 This question already has an answer here : How to handle upper or lower case in JSR 310? [duplicate] (1 answer) Closed 4 years ago . I'm trying to parse date time string to LocalDateTime. However if I send month with all caps its thorwning an error, is there any workaround. Here is the below code @Test public void testDateFormat(){ DateTimeFormatter formatter= DateTimeFormatter.ofPattern("dd-MMM-yyyy HH:mm:ss"); LocalDateTime dateTime = LocalDateTime.parse("04-NOV-2015 16:00:00", formatter);

How to collect Stream<Map<K,V>> into Map<K,List<V>> using java 8?

99封情书 提交于 2020-07-14 06:44:55
问题 I have a stream of Map<String,Double> that I want to collect into a single Map<String,List<Double>> . Does anybody have a suggestion on how to do this? Thanks! 回答1: First you need to flatten your stream of maps into a stream of map entries. Then, use Collectors.groupingBy along with Collectors.mapping: Map<String,List<Double>> result = streamOfMaps .flatMap(map -> map.entrySet().stream()) .collect(Collectors.groupingBy( Map.Entry::getKey, Collectors.mapping(Map.Entry::getValue, Collectors

Jboss AS 7 work with JDK8

早过忘川 提交于 2020-07-11 05:57:29
问题 I'm trying startup JBoss EAP 7.1.1 Final with JDK 1.8.0_144 in Window 7 enviroment. Each time I run the standalone.bat from command line I got following error. Server halt on starting cannot proceed anymore. 09:20:44,413 INFO [org.jboss.modules] JBoss Modules version 1.1.1.GA 09:20:45,203 INFO [org.jboss.msc] JBoss MSC version 1.0.2.GA 09:20:45,265 INFO [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final "Brontes" starting Below is link i download JBoss AS 7.1.1 Final. I also configure my JAVA

Jboss AS 7 work with JDK8

折月煮酒 提交于 2020-07-11 05:57:21
问题 I'm trying startup JBoss EAP 7.1.1 Final with JDK 1.8.0_144 in Window 7 enviroment. Each time I run the standalone.bat from command line I got following error. Server halt on starting cannot proceed anymore. 09:20:44,413 INFO [org.jboss.modules] JBoss Modules version 1.1.1.GA 09:20:45,203 INFO [org.jboss.msc] JBoss MSC version 1.0.2.GA 09:20:45,265 INFO [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final "Brontes" starting Below is link i download JBoss AS 7.1.1 Final. I also configure my JAVA

Jboss AS 7 work with JDK8

走远了吗. 提交于 2020-07-11 05:57:16
问题 I'm trying startup JBoss EAP 7.1.1 Final with JDK 1.8.0_144 in Window 7 enviroment. Each time I run the standalone.bat from command line I got following error. Server halt on starting cannot proceed anymore. 09:20:44,413 INFO [org.jboss.modules] JBoss Modules version 1.1.1.GA 09:20:45,203 INFO [org.jboss.msc] JBoss MSC version 1.0.2.GA 09:20:45,265 INFO [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final "Brontes" starting Below is link i download JBoss AS 7.1.1 Final. I also configure my JAVA

Jboss AS 7 work with JDK8

五迷三道 提交于 2020-07-11 05:57:15
问题 I'm trying startup JBoss EAP 7.1.1 Final with JDK 1.8.0_144 in Window 7 enviroment. Each time I run the standalone.bat from command line I got following error. Server halt on starting cannot proceed anymore. 09:20:44,413 INFO [org.jboss.modules] JBoss Modules version 1.1.1.GA 09:20:45,203 INFO [org.jboss.msc] JBoss MSC version 1.0.2.GA 09:20:45,265 INFO [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final "Brontes" starting Below is link i download JBoss AS 7.1.1 Final. I also configure my JAVA

How to get DayOfWeek from an Instant.now()

走远了吗. 提交于 2020-07-10 05:36:21
问题 Assuming the following code... Instant x = Instant.now(); How do I get day of week from x? 回答1: You have to convert it to ZonedDateTime Instant.now().atZone(ZoneId.systemDefault()).getDayOfWeek() 回答2: I have awarded points to techtabu, but I ended up using atOffset instead. Here is where I ended up... int currentDayOfWeekValue = Instant.now().atOffset(ZoneOffset.UTC).getDayOfWeek().getValue(); I am amazed how difficult the Java8 datetime libraries are. There are so many variations of similar