java-8

Which JAXB version was used in Java 8?

天大地大妈咪最大 提交于 2021-02-08 06:52:49
问题 JAXB (Java Architecture for XML Binding) has been publised as Maven artifacts although it was bundled with JREs until Java 8 (and Java 9/10 with an option). My question here is: Which JAXB version on Maven Central corresponds to Java 8's bundled version? (And, also for Java 9/10's under a feature option?) I'm seeing in https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api : 2.2.* (~ 2.2.12) 2.3.0 2.3.1 2.4.0-* (under development) (3.0.0 to be jakarta.xml.* ) 回答1: As far as Java 8: $ $(

Which JAXB version was used in Java 8?

岁酱吖の 提交于 2021-02-08 06:51:21
问题 JAXB (Java Architecture for XML Binding) has been publised as Maven artifacts although it was bundled with JREs until Java 8 (and Java 9/10 with an option). My question here is: Which JAXB version on Maven Central corresponds to Java 8's bundled version? (And, also for Java 9/10's under a feature option?) I'm seeing in https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api : 2.2.* (~ 2.2.12) 2.3.0 2.3.1 2.4.0-* (under development) (3.0.0 to be jakarta.xml.* ) 回答1: As far as Java 8: $ $(

Java streams zip two lists

此生再无相见时 提交于 2021-02-08 06:22:09
问题 I have a HashSet of Persons. A person has a firstName, lastName and age like: Person("Hans", "Man", 36) My task is to get a list of the persons who are older than 17, sort them by age and concat the firstName with the lastName like: ["Hans Man","another name", "another name"] Im just allowed to import: import java.util.stream.Stream; import java.util.stream.Collectors; import java.util.List; import java.util.ArrayList; My idea was to sort them first, map the names in separate Streams and to

Searching anagrams with Java 8

我只是一个虾纸丫 提交于 2021-02-08 06:14:27
问题 I have to write program which should be reading file for anagrams and show word + his anagrams. Txt files is very big, after using scanner, listOfWords size is: 25000. Output example: word anagram1 anagram2 anagram3 ... word2 anagram1 anagram2... I have code, it works but very slow: private static List<String> listOfWords = new ArrayList<String>(); private static List<ArrayList<String>> allAnagrams = new ArrayList<ArrayList<String>>(); public static void main(String[] args) throws Exception {

Searching anagrams with Java 8

我的未来我决定 提交于 2021-02-08 06:09:51
问题 I have to write program which should be reading file for anagrams and show word + his anagrams. Txt files is very big, after using scanner, listOfWords size is: 25000. Output example: word anagram1 anagram2 anagram3 ... word2 anagram1 anagram2... I have code, it works but very slow: private static List<String> listOfWords = new ArrayList<String>(); private static List<ArrayList<String>> allAnagrams = new ArrayList<ArrayList<String>>(); public static void main(String[] args) throws Exception {

Collection of lambda functions in Java Streams

泄露秘密 提交于 2021-02-08 05:31:14
问题 I have a stream function KStream<K, V>[] branch(final Predicate<? super K, ? super V>... predicates) . I wanted to create a list of predicates dynamically. Is that possible? KStream<Long, AccountMigrationEvent>[] branches = stream .map((key, event) -> enrich(key, event)) .branch(getStrategies()); [...] private List<org.apache.kafka.streams.kstream.Predicate<Long, AccountMigrationEvent>> getStrategies() { ArrayList<Predicate<Long, AccountMigrationEvent>> predicates = new ArrayList<>(); for

Convert ms into a string date with Java 8

Deadly 提交于 2021-02-08 05:25:34
问题 I have a timestamp as ms and format this with a SimpleDateFormater like this: SimpleDateFormat sdfDate = new SimpleDateFormat("MM/d/yyyy h:mm a"); return sdfDate.format(new Date(timeStamp)); Now I'd like to change this to use the new Java 8 abilities. Seems like I really can't find a way to get this working with the new Java 8 Classes. Anyone got a hint? 回答1: If all you have is a millisecond value (assuming from the Unix Epoch) you can get an LocalDateTime using something like: LocalDateTime

Java 8 LocalDateTime and DateTimeFormatter

落花浮王杯 提交于 2021-02-08 04:49:33
问题 below piece of code thorws exception..am i doing something wrong here? DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern( "ddMMuuuuHHmmssSSS" ); String currentTime=FORMATTER.format(LocalDateTime.now()); System.out.println(currentTime); LocalDateTime parsedTime=LocalDateTime.parse(currentTime,FORMATTER); 09042016161444380 Exception in thread "main" java.time.format.DateTimeParseException: Text '09042016161444380' could not be parsed at index 4 at java.time.format.DateTimeFormatter

Set MathContext to BinaryOperator reference methods

霸气de小男生 提交于 2021-02-08 04:27:10
问题 I have this enum: public enum Operator { add("+", BigDecimal::add), subtract("-", BigDecimal::subtract), multiply("*", BigDecimal::multiply), divide("/", BigDecimal::divide), mod("%", BigDecimal::remainder); Operator(final String symbol, final BinaryOperator<BigDecimal> operation) { this.symbol = symbol; this.operation = operation; } public BinaryOperator<BigDecimal> getOperation() { return operation; } } I want to use the some MathContext , one can easily do that when performing an operation

How to cast lambda method parameters?

允我心安 提交于 2021-02-08 03:57:15
问题 I have a lambda expression like below. What I want to ask is Is there any easy way or best practice for casting method parameter? results.forEach( (result) -> { ((JSONObject)result).put("test", "test"); ((JSONObject)result).put("time", System.currentTimeMillis()); otherList.add(((JSONObject)result)); } ); When I try to change input type like (JSONObject result) -> I am getting below error; incompatible types: Consumer<JSONObject> cannot be converted to Consumer<? super Object> 回答1: The error