3 回答

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

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

TA貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超12個(gè)贊
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.
}
}
添加回答
舉報(bào)