'Boolean Supplier Java wait until condition is true
I am trying to get to wait until there exists the condition (theOne, that I am waiting for) in the list of areHere. I am trying to work with BooleanSupplier but can't get it to work, not sure where is my mistake:
String theOne = "pika";
final BooleanSupplier itsHere = () -> {
List <String> areHere = getSomeList();
for (String eachOne : areHere) {
if(eachOne.equals(theOne)) { return TRUE; }
} return FALSE;
};
Solution 1:[1]
you need to execute supplier. You just declared supplier. But not executed.
import java.util.function.BooleanSupplier;
import java.util.*;
public class Main{
public static void main(String[] args) {
String theOne = "pika";
final BooleanSupplier itsHere = () -> {
List <String> areHere = Arrays.asList("1","2","pika");
for (String eachOne : areHere) {
if(eachOne.equals(theOne)) { return Boolean.TRUE; }
} return Boolean.FALSE;
};
Boolean result = itsHere.getAsBoolean(); //this code execute supplier and get result.
System.out.println(result);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Roon |