java-8

For loop to add custom objects to arraylist for n times - Java8

本小妞迷上赌 提交于 2020-01-06 08:12:41
问题 We have an old-style for loop to add custom objects to ArrayList. public List<Object> generateList() { List<Object> list = new ArrayList<Object>(); for (int i = 0; i < 10; i++) { list.add(new Manager(50000, 10, "Finance Manager")); list.add(new Employee(30000, 5, "Accounts")); } return list; } Is there any way to do this by using java8? I tried to use Stream.generate(MyClass::new).limit(10); but, I am not getting the right way in java8 to achieve the above functionality. Any suggestions,

For loop to add custom objects to arraylist for n times - Java8

风流意气都作罢 提交于 2020-01-06 08:12:26
问题 We have an old-style for loop to add custom objects to ArrayList. public List<Object> generateList() { List<Object> list = new ArrayList<Object>(); for (int i = 0; i < 10; i++) { list.add(new Manager(50000, 10, "Finance Manager")); list.add(new Employee(30000, 5, "Accounts")); } return list; } Is there any way to do this by using java8? I tried to use Stream.generate(MyClass::new).limit(10); but, I am not getting the right way in java8 to achieve the above functionality. Any suggestions,

Unable to insert datetimeoffset value using Spring Boot, on SQL Server 2016

回眸只為那壹抹淺笑 提交于 2020-01-06 07:12:34
问题 I have this POJO: public class SomeEntity { private String recordName; private Instant recordDatetime; public SomeEntity(String recordName, Instant recordDateTime) { this.recordName = recordName; this.recordDateTime = recordDateTime; } // Getters and Setters } ...and this corresponding database table defined in a SQL Server 2016 database: CREATE TABLE [dbo].[some_entities]( [record_name] [nvarchar](255) NOT NULL, [record_datetime] [datetimeoffset](7) NOT NULL, CONSTRAINT [PK_some_entities]

Recursively populate JTree, using list of list

僤鯓⒐⒋嵵緔 提交于 2020-01-06 07:11:56
问题 this question has the reverse process in get nested List of CustomObject from JTree, including leaf I want to implement a method optimization of process, I reduced this process simple (multiplication and division) like a Tree shown. The Bottom and Bold Rectangles (the online tool don't let me change the color) represent the total multiplication between N Numerators and D Denominators of each list. Now, I was creating list of list in Java, in order to calculate the total cost of each list

Unable to insert datetimeoffset value using Spring Boot, on SQL Server 2016

半腔热情 提交于 2020-01-06 07:09:24
问题 I have this POJO: public class SomeEntity { private String recordName; private Instant recordDatetime; public SomeEntity(String recordName, Instant recordDateTime) { this.recordName = recordName; this.recordDateTime = recordDateTime; } // Getters and Setters } ...and this corresponding database table defined in a SQL Server 2016 database: CREATE TABLE [dbo].[some_entities]( [record_name] [nvarchar](255) NOT NULL, [record_datetime] [datetimeoffset](7) NOT NULL, CONSTRAINT [PK_some_entities]

Java 8 parallel streams don't appear to actually be working in parallel

最后都变了- 提交于 2020-01-06 07:00:29
问题 I'm trying to use Java 8's parallelStream() to execute several long-running requests (eg web requests) in parallel. Simplified example: List<Supplier<Result>> myFunctions = Arrays.asList(() -> doWebRequest(), ...) List<Result> results = myFunctions.parallelStream().map(function -> function.get()).collect(... So if there are two functions that block for 2 and 3 seconds respectively, I'd expect to get the result after 3 seconds. However, it really takes 5 seconds - ie it seems the functions are

JavaFX FXML Application won't run

喜你入骨 提交于 2020-01-06 05:51:46
问题 I'm trying to follow the tutorial here. But, my IDE, Eclipse, doesn't seem to want to work with it. I've tried copying and pasting the code examples into my IDE, but the same error pops up. Unfortunately, no window is displayed. Please help me figure out what's wrong with this code. The error: Exception in Application start method java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke

Java 8 conditional .map() (or map with identity function)

一世执手 提交于 2020-01-06 03:39:47
问题 Suppose we have boolean flag to turn on/off map in a stream. For example to trim or not. Are the below examples proper solution or there is a better way to implement that? boolean doTrim = true; optionalValue.map(doTrim ? String::trim : (x) -> x ).get()... or: boolean doTrim = true; optionalValue.map(doTrim ? String::trim : Function.identity() ).get()... 回答1: You are over-complicating things. If you have an Optional<String> optionalValue you can simply say: if(doTrim) optionalValue

RC4 related issue after Java 8 update

好久不见. 提交于 2020-01-06 03:16:25
问题 In previous version of Java RC4 was enabled at that time my app worked fine but after Java 8 U 77 update it doesn't any more use the following ciphers which are need to work with one of my legacy servers. TLS_ECDHE_ECDSA_WITH_RC4_128_SHA TLS_ECDHE_RSA_WITH_RC4_128_SHA SSL_RSA_WITH_RC4_128_SHA TLS_ECDH_ECDSA_WITH_RC4_128_SHA TLS_ECDH_RSA_WITH_RC4_128_SHA SSL_RSA_WITH_RC4_128_MD5 I modified the java.security and the disabled algorithm section look like below, jdk.certpath.disabledAlgorithms=MD2

tools.jar missing - but only on the very first call (Tomcat 8/Java 8/ Axis)

[亡魂溺海] 提交于 2020-01-06 02:26:29
问题 Now that I upgraded my webapp to Java 8, I'm running into strange classloading problem with an axis webservice that is running in Tomcat 8. The very first call to the webservice after installing the webapp will cause a RuntimeException and a "No compiler found in your classpath! (you may need to add 'tools.jar')" fault. All following calls to that webservice work correctly (apparently tools.jar is there after all?). The behaviour is reproducable by deleting the exploded webapp folder in the