简体   繁体   中英

How to get a key value and do some action with the value in a hashmap

DatePicker dp = new DatePicker();
        dp.setDayCellFactory(picker -> new DateCell() {
            public void updateItem(LocalDate date, boolean empty) {
                super.updateItem(date, empty);
                LocalDate today = LocalDate.now();

                setDisable(empty || date.compareTo(today) < 0 );

            }
        });
        /*This switch button will only allow to switch scenes if a date is selected*/
        Button swtich = new Button("Add other details");
        swtich.setOnAction(new EventHandler<ActionEvent>() {
            @Override public void handle(ActionEvent e) {
                if (dp.getValue() == null)
                {
                    a.setAlertType(Alert.AlertType.WARNING);
                    a.setHeaderText("Enter a proper date !");
                    a.showAndWait();


                }
                else {
                    LocalDate localDate = dp.getValue();
                    stage01.setScene(scene01);
                }


            }
        });

Now the localdate gets saved in the hashmap with seat number as soon as the user enters the other required details

DateDetails.put(dp.getValue(),seatC);

Now i want to compare this date which is stored in DateDetails with a date picked up by the user. if its already stored in the hashmap then i want to get the seatC which is that seats and then disable the previous stored seats

This is the output i get when i save the required details in the hashmap,so everything is fine with the hashmap but i dont have an idea on how to compare the new chose date with the previous stored date

Have you tried using .keySet() ? .keySet() gives you an array of the keys, and then you could iterate through that array of keys to do your desired operation.

For example, say you have a HashMap called food

food.put("apple", 1);
food.put("orange", 2):

Then you can just iterate through they keys by:

for(String k: food.keySet()) {
//do whatever
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM