使用javafx中的hashmap在两个日期之间列出日期和值 [英] List of dates and values between the two dates using hashmap in javafx

查看:140
本文介绍了使用javafx中的hashmap在两个日期之间列出日期和值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能解释一下如何使用hashmap显示两个日期之间的日期和整数值,它应该在javafx的listview中显示。



示例:假设,我需要10-02-2017和20-02-2017之间的日期和值,以便日期和值仅显示在这些值之间。



10-02-2017 10

11-02-2017 17

12-02-2017 15







20-02-2017 17



我尝试了什么:



这是我一直在尝试的以下代码,但它收到错误< br $> b $ b

Can you explain how to display the dates and integer values between two dates using hashmap, and it should be displayed in listview in javafx.

Example: Suppose, I need the dates and values between 10-02-2017 and 20-02-2017, so that the dates and the values are displayed between those values only.

10-02-2017 10
11-02-2017 17
12-02-2017 15
.
.
.
20-02-2017 17

What I have tried:

This is the following code I've been trying but it's getting error

@FXML
    private Map<Date,Integer> map=new HashMap<Date,Integer>();
    @FXML
    private ListView listview = new ListView();


            Date date1=new Date();
            Date date2=new Date();
            
            map.put(date1, 10);
            map.put(date2,20);
            
            listItems.add(map.get(date1));
            listItems.add(map.get(date2));
            
            for(Map.Entry<Date, Integer>entry: map.entrySet())
            {
                String d="Number of entries for "+entry.getKey().toString()+" = "+entry.getValue();
                listItems.add(d);
            }
             listview.setItems(listItems);
        }

推荐答案

listItems.add(map.get(date1));



您对 map.get 的调用会返回一个整数值(10,20等),但 listItems.add 需要一个字符串。



如错误消息中所述。


Your call to map.get returns an integer value (10, 20 etc) but listItems.add requires a String.

As clearly stated in the error messages.


这篇关于使用javafx中的hashmap在两个日期之间列出日期和值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆