HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavaModerate

Looping over a list, checking a boolean and return value

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
loopingbooleanreturncheckingvalueandlistover

Problem

There are a number of different ways to do this. What do people prefer and why?

public boolean checkNameStartsWith(List foos) {
    for (Foo foo : foos) {
        if (!(foo.getName().startsWith("bar"))) {
            return Boolean.FALSE;
        }
    }
    return Boolean.TRUE;
}

Solution

I'd change Boolean.FALSE to false and Boolean.TRUE to true. Using the constants objects from Boolean is rather unnecessary since the method returns with primitive boolean.

Context

StackExchange Code Review Q#18302, answer score: 14

Revisions (0)

No revisions yet.