1. import java.util.List;
  2. public class HypothesisValidator {
  3. /**
  4. * Searches a list of lists for a specific hypothesis.
  5. *
  6. * @param listOfLists The list of lists to search.
  7. * @param hypothesis The hypothesis to search for.
  8. * @return True if the hypothesis is found in any of the inner lists, false otherwise.
  9. */
  10. public static boolean validateHypothesis(List<List<String>> listOfLists, String hypothesis) {
  11. if (listOfLists == null || hypothesis == null) {
  12. return false; // Handle null inputs
  13. }
  14. for (List<String> innerList : listOfLists) {
  15. if (innerList != null && innerList.contains(hypothesis)) {
  16. return true; // Hypothesis found
  17. }
  18. }
  19. return false; // Hypothesis not found
  20. }
  21. public static void main(String[] args) {
  22. // Example Usage
  23. List<List<String>> data = List.of(
  24. List.of("apple", "banana", "orange"),
  25. List.of("grape", "kiwi", "apple"),
  26. List.of("mango", "pineapple", "strawberry")
  27. );
  28. String hypothesis1 = "apple";
  29. String hypothesis2 = "watermelon";
  30. System.out.println("Hypothesis '" + hypothesis1 + "' validated: " + validateHypothesis(data, hypothesis1)); //true
  31. System.out.println("Hypothesis '" + hypothesis2 + "' validated: " + validateHypothesis(data, hypothesis2)); //false
  32. }
  33. }

Add your comment