fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.stream.* ;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. String s = "Downloaded";
  14. Map<String, List<String>> map = Map.ofEntries(
  15. Map.entry( "Download", List.of( "Download", "Downloading", "Downloaded" ) ) ,
  16. Map.entry( "Upload", List.of( "Upload", "Uploading", "Uploaded" ) )
  17. );
  18. System.out.println( map ) ;
  19.  
  20. Collection < String > keys =
  21. map
  22. .entrySet()
  23. .stream()
  24. .filter( ( Map.Entry < String, List<String> > entry ) -> entry.getValue().contains( s ) )
  25. .map( Map.Entry :: getKey )
  26. .collect( Collectors.toUnmodifiableList() ) // Or replace with `.toList()` in more modern Java.
  27. ;
  28. System.out.println( keys ) ;
  29. }
  30. }
Success #stdin #stdout 0.09s 53976KB
stdin
Standard input is empty
stdout
{Upload=[Upload, Uploading, Uploaded], Download=[Download, Downloading, Downloaded]}
[Download]