Imagine you’re a Java programmer. You need to iterate across a list of strings. Your natural instinct might be to just use a for loop, and that’s proof that you’re not a true enterprise Java programmer.

Diether’s company is home to true enterprise developers, and they know how to get things done.

List<String> brandSpecValues = specValueDao.getBrandSpecValues();
boolean brndValueFound = false;
String listString = brandSpecValues.toString().replace("[", "");
listString = listString.replace("]", "");
String[] arr = listString.split(",");
for (String s : arr) {
        if (s.trim().equals(brandSpecValueString.toUpperCase())) {
                brndValueFound = true;
        }
}

Why iterate across a list when you can turn the list into a string first then turn it back into an array? For a moment, I thought, “well, maybe the interface to the DAO changed to use Generics and they were trying to minimize code changes?” But that makes no sense, because the only thing they would have needed to change was the type of brandSpecValues. I’m left with one conclusion: they just really like Strings.

For bonus points, the array contains only 5 values ever, and this block of code is called from inside of a for loop that runs thousands of times in a row.

[Advertisement] Application Release Automation for DevOps – integrating with best of breed development tools. Free for teams with up to 5 users. Download and learn more today!