Refactor method to Java 8 I have a method that iterate a list of maps if a certain element is found then set value of certain variables and break the loop.
I'm trying to revamp this into Java 8. And further if it can be improved, please suggest.

public static void doAction(List&lt;Map&lt;String, String&gt;&gt; decisionTree, String code, StringBuilder destination) {
    boolean conditionFound = false;
    boolean decisionFound = false;
    for (int i = 0; i &lt; 100; i++) {
        if (null != decisionTree) {
            for (Map&lt;String, String&gt; decisionMap : decisionTree) {
                if (null != decisionMap &amp;&amp; code.equalsIgnoreCase(decisionMap.get("code"))) {
                    decisionFound = true;
                    String decision = decisionMap.get("is_success");
                    String decisionAction = decisionMap.get("action");

                    BiPredicate&lt;String, String&gt; isApplicable = (d, a) -&gt; "N".equalsIgnoreCase(d) &amp;&amp; "Z".equalsIgnoreCase(a);

                    if (isApplicable.test(decision, decisionAction)) {
                        destination.append(decisionMap.get("destination"));
                        conditionFound = Boolean.TRUE;
                    }
                    break;
                }
            }
            if(decisionFound){
                if(conditionFound){
                    // do something
                    break;
                }
            }
        }
    }
}
Probably not the right forum.

In java f(x) the method f will never change the variable x to another value; it cannot be make it null or true or whatever. (A rule to prevent a category of errors.)

So you want a result:

public static class Decision {
    String destination;
    boolean conditionFound;
}


As in java null's should in normal code not be valid, I did not test them.
A test however would not need:

if (null != decisionTree) { // Typical C style.


but can be

if (decisionTree != null) {


As the following is not legal java:

if (decisionTree = null) { // *** Illegal java. // Run-time error in C (assignment).


Searching the code entry result results in an Optional&lt;Decision&gt;.

public static Optional&lt;Decision&gt; doAction(List&lt;Map&lt;String, String&gt;&gt; decisionTree,
            String code) {
    decisionTree.stream()
        .findAny(decisionMap -&gt; code.equalsIgnoreCase(decisionMap.get("code")))
        .map(decisionMap -&gt; {
            Decision decision = new Decision();

            String success = decisionMap.get("is_success");
            String action = decisionMap.get("action");
            BiPredicate&lt;String, String&gt; isApplicable = (s, a) -&gt;
                    "N".equalsIgnoreCase(s) &amp;&amp; "Z".equalsIgnoreCase(a);

            if (isApplicable.test(success, action)) {
                decision.destination = decisionMap.get("destination");
                decision.conditionFound = true;
            }
            return decision
        });
}

Optional&lt;Decision&gt; optionalDecision = doAction(decisionTree, code);
optionalDecision.ifPresent(decision -&gt; {
    if (decision.conditionFound) {
        System.out.println(destination);
    }
});


A BiPredicate is not really needed, but not bad.

Instead of a result object, one could also pass an in-out parameter:

public static class DecisionParameter {
    boolean decisionFound;
    StringBuilder destination;
    boolean conditionFound;
}