fork(3) 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.regex.*;
  7. import java.util.stream.*;
  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. List<String> models = Arrays.asList("Accord", "Civic", "Element");
  15. System.out.println("First: " + compareTwoList(models, Arrays.asList("2014 Honda Accord", "2011 Toyota Camry")));
  16. System.out.println("Second: " + compareTwoList(models, Arrays.asList("2013 Honda Accord", "2015 Honda Element", "2011 Honda Civic")));
  17. }
  18.  
  19. public static boolean compareTwoList(List<String> models, List<String> titleOfVehicles) {
  20.  
  21. String pattern = models.stream()
  22. .map(Pattern::quote)
  23. .collect(Collectors.joining("|", ".*(", ").*"));
  24.  
  25. Pattern re = Pattern.compile(pattern);
  26.  
  27. return titleOfVehicles.stream().allMatch(t -> re.matcher(t).matches());
  28.  
  29. }
  30. }
Success #stdin #stdout 0.26s 321024KB
stdin
Standard input is empty
stdout
First: false
Second: true