[LeetCode] – 125. The Valid Palindrome
In this problem, I encountered a new method to determine whether a string is a letter or a number. Here’s an explanation.
Use isDigit to determine if it is a number
public static boolean isNumeric(String str){
for (int i = str.length();--i>=0;){
if (!Character.isDigit(str.charAt(i))){
return false;
}
}
return true;
}
Use isLetter to determine if it is a letter
public class Test{
public static void main(String args[]){
System.out.println( Character.isLetter('c'));
System.out.println( Character.isLetter('5'));
}
}
Results:
true
false
Read More:
- Java compareto() method
- Java – read all the files and folders in a certain directory and three methods to get the file name from the file path
- Compare whether two sets are the same in Java
- The differences between the equals method in the string class and the equals method in the object class
- Destructor abnormal stuck bug
- [Two Sigma OA] Longest Chain
- Conversion between list and string array
- Java gets the type t.class of generic t
- The method of Java jumping out of loop
- The solution cannot be separated due to a special separator
- Java 8 Stream – Read a file line by line
- Java uses the same event listener for the same type of component
- Java – how to shuffle an ArrayList
- non-static variable this cannot be referenced from a static context
- Realize the simplest recursive call, simulate exception in thread “main” java.lang.stackoverflowerror exception
- Encapsulation of adding, deleting and modifying database by JDBC
- JAVA lambda Syntax error on tokens, Expression expected instead
- About Java File.separator
- Difference between isempty method and isblank method in stringutils
- Implementation of multithread sequential alternate execution by using lock in Java