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 the array to accomplish this, but I want to do it through regex.
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 the array to accomplish this, but I want to do it through regex.
Copyright © 2021 Jogjafile Inc.
The regex is rather simple:
The first part says that
AthroughCcould be followed by an optional plus or minus; the second part allows aDby itself.You could also use
contains(), to do it without a loop: