I have an array
String[] grades = new String[]{"D","C-","C","C+","B-","B","B+","A-","A","A+"};
I want to check if a string is one of these values.
I could loop through an array to execute this, but I want to do this through a regex.
The regex is pretty simple:
[AC][+-]?|D
The first part says that A through C can be followed by an additional plus or minus; the second part allows D himself.
A
C
D
I could go through the array to execute this
You can also use contains() to do this without a loop:
contains()
if (Arrays.asList(grades).contains(grade)) { ... }