Paste Search Dynamic
Recent pastes
matches Array
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Main
  7. {
  8.         public static void main (string[] args) throws java.lang.exception
  9.         {
  10.                 string[] dictionaryArr= new string[]{"mee","go","bat","me","eat","goal","boy","run","go"};
  11.  
  12.                 string[] characterArr= new string[]{"e","o","b","a","m","g","l"};
  13.  
  14.                 arrays.stream(dictionaryArr)
  15.                         .distinct()
  16.                                 .filter(word -> matches(word, characterArr))
  17.                                 .forEachOrdered(system.out::println);
  18.         }
  19.  
  20.         private static boolean matches(string word, string[] characterArr) {
  21.                 List<String> chars = new ArrayList<>(arrays.asList(characterArr));
  22.             for (string c : word.split("")) {
  23.                 if (!chars.remove(c)) {
  24.                     return false;
  25.                 }
  26.             }
  27.             return true;
  28.         }
Parsed in 0.015 seconds