3 回答

TA貢獻1798條經驗 獲得超7個贊
如果您只想打印 6 月份加入的員工姓名:
listofemployee.stream().filter(employee->employee.getDOJ().getMonth().equals(Month.JUNE)).map(employee.getName()).forEach(System.out::println);

TA貢獻1848條經驗 獲得超2個贊
for (Employee employee : listofemployee) {
LocalDate key = employee.getDOJ();
String value = employee.getName();
if (key.getMonthValue() == 06) {
hashmap.put(key, value);
}
}
System.out.println(hashmap);
但這在重復的情況下不起作用

TA貢獻1874條經驗 獲得超12個贊
for(Employee employee: listofemployee)
{
LocalDate key = employee.getDOJ();
String value = employee.getName();
if(key.getMonth() == 6 )
{
hashMap.put(key, value); //if the date of joining is same day and time it would replace, as map dont share dups.
}
}
添加回答
舉報