Details
-
Wish
-
Status: Closed
-
Minor
-
Resolution: Won't Fix
-
3.2.1
-
None
-
None
Description
Example use case:
If a Method expects values that should only consist of a certain set such as "0" and "1", and any Invalid String should be defaulted to "0".
Possible Solution:
public static String defaultIfNotIn(final String str, final String defaultString, String... validStrings) { if (str == null) { return defaultString; } for (final String validString : validStrings) { if (validString.equals(str)) { return str; } } return defaultString; }