If your input is a character and the characters you are checking against are mostly consecutive you could try this:
if ((symbol >= 'A' && symbol <= 'Z') || symbol == '?') { // ... }
However if your input is a string a more compact approach (but slower) is to use a regular expression with a character class:
if (symbol.matches("[A-Z?]")) { // ... }
If you have a character you’ll first need to convert it to a string before you can use a regular expression:
if (Character.toString(symbol).matches("[A-Z?]")) { // ... }
Related Posts:
- How to convert a char to a String?
- How to convert/parse from String to char in java?
- “Char cannot be dereferenced” error
- “Char cannot be dereferenced” error
- How can I convert a char to int in Java? [duplicate]
- Convert int to char in java
- Illegal Escape Character “\”
- Char Comparison in C
- How to compare dates in Java?
- How do I apply the for-each loop to every character in a String?
- Understanding the difference between null and ‘\u000’ in Java
- Understanding the difference between null and ‘\u000’ in Java
- Use ‘=’ or LIKE to compare strings in SQL?
- Char Comparison in C
- Unclosed Character Literal error
- How is __eq__ handled in Python and in what order?
- Java Not Greater than Or Equal to Operator for Char Type
- Value for epsilon in Python
- Comparison operator
- Want to make a web page that should work like [closed]
- Exception in thread “main” java.util.NoSuchElementException
- “Error occurred during initialization of VM; Could not reserve enough space for object heap” using -Xmx3G
- What’s the simplest way to print a Java array?
- javax vs java package
- What is a stack trace, and how can I use it to debug my application errors?
- How to fix “A JNI error has occurred, please check your installation.”
- Java Runtime Environment not found error when I open an application
- “PKIX path building failed” and “unable to find valid certification path to requested target”
- What exactly does a jar file contain?
- java – invalid method declaration; return type required [duplicate]
- Java optional parameters
- What is the difference between == and equals() in Java?
- Exception in Application start method java.lang.reflect.InvocationTargetException
- Error when checking Java version: could not find java.dll
- how to fix java.lang.IndexOutOfBoundsException
- Understanding Spring @Autowired usage
- What does the arrow operator, ‘->’, do in Java?
- Switch on Enum in Java
- Converting JSON data to Java object
- error upon assigning Layout: BoxLayout can’t be shared
- Why do this() and super() have to be the first statement in a constructor?
- Else without if
- Keytool is not recognized as an internal or external command
- Cannot find “Package Explorer” view in Eclipse
- Error: Could not find or load main class in intelliJ IDE
- Java Hashmap: How to get key from value?
- Simple Java HTTPS server
- java.net.ConnectException :connection timed out: connect?
- Java – String cannot be converted to int
- restart console on Minecraft Server
- SSL peer shut down incorrectly in Java
- Java split string to array
- Pyspark: Exception: Java gateway process exited before sending the driver its port number
- How can I clear or empty a StringBuilder?
- Javamail Could not convert socket to TLS GMail
- java.net.SocketException: Connection reset
- Cannot instantiate the type Queue. Why is this?
- How do I instantiate a Queue object in java?
- Pause the timer and then continue it
- Java substring: ‘string index out of range’
- Eclipse returns error message “Java was started but returned exit code = 1”
- throw checked Exceptions from mocks with Mockito
- Escape Character in SQL Server
- How to sort an array of objects in Java?
- Android – SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
- Hibernate Error: a different object with the same identifier value was already associated with the session
- How to solve the “failed to lazily initialize a collection of role” Hibernate exception
- Convert char array to single int?
- Initializing multiple variables to the same value in Java
- Java: Unresolved compilation problem
- FXML Load exception
- NullPointerExcetion Native Method Accessor… Hashing Words Issue
- How to convert currentTimeMillis to a date in Java?
- How to clear console in Java – Eclipse
- Java TreeMap Comparator
- How do I run Java .class files?
- Fill an array with random numbers [duplicate]
- Java check if boolean is null
- Connection Java – MySQL : Public Key Retrieval is not allowed
- What is SuppressWarnings (“unchecked”) in Java?
- Whitespace Matching Regex – Java
- Size has private access in ArrayList
- Iterator for a linkedlist
- Hide Utility Class Constructor : Utility classes should not have a public or default constructor
- get char value in java
- Syntax error, insert “… VariableDeclaratorId” to complete FormalParameterList
- Android – Start service on boot
- JsonMappingException: No suitable constructor found for type [simple type, class ]: can not instantiate from JSON object
- What is a hash function in java?
- How to extract .war files in java? ZIP vs JAR
- What is the difference between run-time error and compiler error?
- What is the difference between ArrayList.clear() and ArrayList.removeAll()?
- Java says this method has a constructor name
- Test if element is present using Selenium WebDriver?
- Increase heap size in Java
- TicTacToe with GUI in Java
- Spring Boot – Cannot determine embedded database driver class for database type NONE
- Convert double to float in Java
- How to display checked posts on another page over AJAX? (like comparasion style)
- Comparing Time with the_time();