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. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String[] dictionaryArr= new String[]{"mee","go","bat","me","eat","goal","boy","run","go"};
  13.  
  14. String[] characterArr= new String[]{"e","o","b","a","m","g","l"};
  15.  
  16. Arrays.stream(dictionaryArr)
  17. .distinct()
  18. .filter(word -> matches(word, characterArr))
  19. .forEachOrdered(System.out::println);
  20. }
  21.  
  22. private static boolean matches(String word, String[] characterArr) {
  23. List<String> chars = new ArrayList<>(Arrays.asList(characterArr));
  24. for (String c : word.split("")) {
  25. if (!chars.remove(c)) {
  26. return false;
  27. }
  28. }
  29. return true;
  30. }
  31. }
Success #stdin #stdout 0.09s 48492KB
stdin
Standard input is empty
stdout
go
me
goal