Here is one way to do it with regular expressions:
if (Pattern.matches("\\p{Punct}", str)) {
...
}
The \p{Punct}
regular expression is a POSIX pattern representing a single punctuation character.
More Related Contents:
- Check whether a string is not null and not empty
- Similarity String Comparison in Java
- String comparison and String interning in Java
- String Comparison in Java
- Comparing a string with the empty string (Java)
- String comparison with logical operator in Java
- Java Exercise: about the output
- How can I convert List to int[] in Java? [duplicate]
- How do I iterate through the files in a directory and it’s sub-directories in Java?
- Http Basic Authentication in Java using HttpClient?
- Is it possible in Java to access private fields via reflection [duplicate]
- What’s the difference between Spring Data’s MongoTemplate and MongoRepository?
- How to use YamlPropertiesFactoryBean to load YAML files using Spring Framework 4.1?
- what does it mean when they say http is stateless
- How to convert a String into an ArrayList?
- Mapping list in Yaml to list of objects in Spring Boot
- Find top N elements in an Array
- interface and a class. name clash: same erasure, yet neither overrides other
- Ignoring property when deserializing
- Detect a key press in console
- Remove all non-“word characters” from a String in Java, leaving accented characters?
- Building with Intellij 2017.2 /out directory duplicates files in /build directory
- How do I call a UDF on a Spark DataFrame using JAVA?
- How to call a method before the session object is destroyed?
- How to Iterate through HashMap in MyBatis foreach?
- Java Interface Usage Guidelines — Are getters and setters in an interface bad?
- substring method in String class causes memory leak [duplicate]
- How to set the content type on the servlet
- Log4J: Strategies for creating Logger instances
- Creating circular generic references