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.util.stream.Collectors;
  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 < String, List < Integer > > map =
  15. Map.of(
  16. "alice" , List.of( 1 , 2 , 3 ) ,
  17. "bob" , List.of( 4 , 5 , 6 ) ,
  18. "paul" , List.of( 10 , 11 )
  19. );
  20.  
  21. List < Integer > orders = List.of( 1 , 2 , 3 , 4 , 5 , 6 , 7 );
  22.  
  23. List < String > customersOfTargtedOrderIds =
  24. map
  25. .entrySet()
  26. .stream()
  27. .filter( e -> e.getValue().stream().anyMatch( orders :: contains ) )
  28. .map( Map.Entry :: getKey )
  29. .collect( Collectors.toList() ); // Or just `.toList()` in modern Java.
  30.  
  31. System.out.println( "customersOfTargtedOrderIds = " + customersOfTargtedOrderIds );
  32. }
  33. }
Success #stdin #stdout 0.13s 50948KB
stdin
Standard input is empty
stdout
customersOfTargtedOrderIds = [alice, bob]