fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.time.* ;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. Map< DayOfWeek , String > dailyAssignment = new EnumMap<>( DayOfWeek.class ) ;
  15. dailyAssignment.put( DayOfWeek.MONDAY, "Alice" ) ;
  16. dailyAssignment.put( DayOfWeek.TUESDAY, "Bob" ) ;
  17. dailyAssignment.put( DayOfWeek.SATURDAY, "Bob" ) ;
  18. dailyAssignment.put( DayOfWeek.SUNDAY, "Carol" ) ;
  19.  
  20. List< DayOfWeek > weekend = List.of( DayOfWeek.SATURDAY , DayOfWeek.SUNDAY ) ;
  21.  
  22. Map< DayOfWeek , String > weekendAssignment = new EnumMap<>( dailyAssignment ) ;
  23. weekendAssignment.keySet().retainAll( weekend ) ;
  24.  
  25. System.out.println( "dailyAssignment.toString(): " + dailyAssignment ) ;
  26. System.out.println( "weekendAssignment.toString(): " + weekendAssignment ) ;
  27. }
  28. }
Success #stdin #stdout 0.14s 36500KB
stdin
Standard input is empty
stdout
dailyAssignment.toString(): {MONDAY=Alice, TUESDAY=Bob, SATURDAY=Bob, SUNDAY=Carol}
weekendAssignment.toString(): {SATURDAY=Bob, SUNDAY=Carol}