fork(1) 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. private static final String SOME_CONSTANT = "A";
  11.  
  12. private static boolean java7(List<String> variables,List<String> attrNames){
  13. for (String variable : variables) {
  14. boolean validAttribute = false;
  15. if (variable.equals(SOME_CONSTANT)) {
  16. validAttribute = true;
  17. } else {
  18. for (String attrName : attrNames) {
  19.  
  20. if (variable.equals(attrName)) {
  21. validAttribute = true;
  22. break;
  23. }
  24. }
  25. }
  26. if (!validAttribute) {
  27. return false;
  28. }
  29. }
  30. return true;
  31. }
  32.  
  33. private static boolean java8(List<String> variables,List<String> attrNames){
  34. return variables.stream().allMatch((item) -> item.equals(SOME_CONSTANT) || attrNames.contains(item));
  35. }
  36.  
  37. public static void main (String[] args) throws java.lang.Exception
  38. {
  39. List<String> attrNames = Arrays.asList("a", "b", "c");
  40. List<String> noMatch = Arrays.asList("x", "b", "c");
  41. List<String> match = Arrays.asList("a", "b", "c");
  42. List<String> constant = Arrays.asList("a", "b", "c");
  43.  
  44. System.out.println(java7(noMatch,attrNames)+" "+java8(noMatch,attrNames));
  45. System.out.println(java7(match,attrNames)+" "+java8(match,attrNames));
  46. System.out.println(java7(constant,attrNames)+" "+java8(constant,attrNames));
  47.  
  48. }
  49. }
Success #stdin #stdout 0.17s 320576KB
stdin
Standard input is empty
stdout
false false
true true
true true