java if `String` begins with "red" or "blue"
Why aren't you using String.startsWith(prefix)?  This should be a one-liner.

return str.startsWith("red")  ? "red"  :
       str.startsWith("blue") ? "blue" : "";