import java.util.List;
public class HypothesisValidator {
/**
* Searches a list of lists for a specific hypothesis.
*
* @param listOfLists The list of lists to search.
* @param hypothesis The hypothesis to search for.
* @return True if the hypothesis is found in any of the inner lists, false otherwise.
*/
public static boolean validateHypothesis(List<List<String>> listOfLists, String hypothesis) {
if (listOfLists == null || hypothesis == null) {
return false; // Handle null inputs
}
for (List<String> innerList : listOfLists) {
if (innerList != null && innerList.contains(hypothesis)) {
return true; // Hypothesis found
}
}
return false; // Hypothesis not found
}
public static void main(String[] args) {
// Example Usage
List<List<String>> data = List.of(
List.of("apple", "banana", "orange"),
List.of("grape", "kiwi", "apple"),
List.of("mango", "pineapple", "strawberry")
);
String hypothesis1 = "apple";
String hypothesis2 = "watermelon";
System.out.println("Hypothesis '" + hypothesis1 + "' validated: " + validateHypothesis(data, hypothesis1)); //true
System.out.println("Hypothesis '" + hypothesis2 + "' validated: " + validateHypothesis(data, hypothesis2)); //false
}
}
Add your comment