java-8

Map alternative for primitive values

旧时模样 提交于 2021-02-06 09:42:07
问题 I did some profiling on my application and one of the results turned out that about 18% of memory on the heap is used by objects of type Double . It turns out these objects are the values in Map s, where I cannot use the primitive type. My reasoning is that the primitive type of double consumes less memory than it's object Double . Is there a way to have a map like data structure, that would accept any type as key and a primitive double as values? Main operations would be: insertion (probably

What's the difference between groupingby and mapping in Collectors (Java)?

若如初见. 提交于 2021-02-06 08:43:34
问题 Take a look at this piece of code. // group by price, uses 'mapping' to convert List<Item> to Set<String> Map<BigDecimal, Set<String>> result = items.stream().collect( Collectors.groupingBy(Item::getPrice, Collectors.mapping(Item::getName, Collectors.toSet()) ) ); Is groupingBy and Mapping interchangeable? What is their differences? For the third parameter in collect(), would I get the same output type Map if I used Collectors.toList() instead of Collectors.toSet()? I heard that toList() is a

LocalDateTime remove the milliseconds

人盡茶涼 提交于 2021-02-05 12:58:15
问题 I am working in java application where i am using the Java 8. I have integrated the database(multiple database Oracle,Mysql,Postgres) and where in DB i string the created date. the date format in DB is - 2015-07-29 16:23:28.143 I fetch this from DB and set in Localdatetime object myObj.setCreated(rs.getTimestamp("created").toLocalDateTime()); So here the issue is i dont want to show/send the millisecond in the response. i want to show/send date like 2015-07-29 16:23:28 I tried the formatter

LocalDateTime remove the milliseconds

我是研究僧i 提交于 2021-02-05 12:58:14
问题 I am working in java application where i am using the Java 8. I have integrated the database(multiple database Oracle,Mysql,Postgres) and where in DB i string the created date. the date format in DB is - 2015-07-29 16:23:28.143 I fetch this from DB and set in Localdatetime object myObj.setCreated(rs.getTimestamp("created").toLocalDateTime()); So here the issue is i dont want to show/send the millisecond in the response. i want to show/send date like 2015-07-29 16:23:28 I tried the formatter

Why am I getting a parse exception when I try to parse the current LocalDateTime [duplicate]

你说的曾经没有我的故事 提交于 2021-02-05 12:36:45
问题 This question already has answers here : Can’t rid of 'T' in LocalDateTime (3 answers) Closed 1 year ago . I am trying to parse a LocalDate with a custom formatter but it is throwing following error. What am I doing wrong? Error: // The local date time now value is 2019-09-19T14:42:23.837 java.time.format.DateTimeParseException: Text '2019-09-19T14:42:23.837' could not be parsed at index 10 Code: DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");

Why am I getting a parse exception when I try to parse the current LocalDateTime [duplicate]

老子叫甜甜 提交于 2021-02-05 12:34:41
问题 This question already has answers here : Can’t rid of 'T' in LocalDateTime (3 answers) Closed 1 year ago . I am trying to parse a LocalDate with a custom formatter but it is throwing following error. What am I doing wrong? Error: // The local date time now value is 2019-09-19T14:42:23.837 java.time.format.DateTimeParseException: Text '2019-09-19T14:42:23.837' could not be parsed at index 10 Code: DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");

For a given Date object, capture it's value relevant to GMT timezone

╄→гoц情女王★ 提交于 2021-02-05 10:39:34
问题 In my application running on Java 8, I have a Date object. The timezone for this object depends on the client's location. At one particular point, I need to convert this Date to GMT so that it could be comparable to a value that I access from the DB. I tried SimpleDateFormat and ZonedDateTime, but there's a pain-point. These API's provide me GMT time in String values, which is perfectly fine. However, once I parse it and assign it to a Date object, it is back to my local timezone! For Ex:

For a given Date object, capture it's value relevant to GMT timezone

主宰稳场 提交于 2021-02-05 10:38:29
问题 In my application running on Java 8, I have a Date object. The timezone for this object depends on the client's location. At one particular point, I need to convert this Date to GMT so that it could be comparable to a value that I access from the DB. I tried SimpleDateFormat and ZonedDateTime, but there's a pain-point. These API's provide me GMT time in String values, which is perfectly fine. However, once I parse it and assign it to a Date object, it is back to my local timezone! For Ex:

Dynamically update Combobox after selecting item in another ComboBox - JavaFX

时间秒杀一切 提交于 2021-02-04 20:59:21
问题 I have a JavaFX form with two combo boxes populated with Times in 15 min increments for Start and End times. I am trying to get the End time combo box to dynamically repopulate with options when the user selects a start time so that it is not possible for the user to select an End time before the start time while preserving the user's selection if the user has already selected an end time that is still after the start time. I have been able to get both boxes to populate correctly and

How to compare two ArrayList and get list1 with filter using java streams

百般思念 提交于 2021-02-04 19:36:07
问题 I have two lists list1 & list2 of type List Term{ long sId; int rowNum; long psid; String name; } List<Term> list1 = new ArrayList<>(); List<Term> list2 = new ArrayList<>(); I want to return all the items from list1 where (list1.psid != list2.psid). I tried this but its not working public List<Term> getFilteredRowNum(List<Term> list1, List<Term> list2) { List<Long> psid = list2.stream().map(x -> x.getPsid()).collect(Collectors.toList()); return list1.stream().filter(x -> !psid.contains(x