Cet article résume la méthode de Java pour déterminer si une chaîne est un nombre. Partagez-le pour votre référence, comme suit:
Méthode 1: Utilisez les fonctions fournies avec Java
public static boolean isNumeric (String str) {for (int i = str.length (); - i> = 0;) {if (! Caract.IsDigit (str.charat (i))) {return false; retour true;}Méthode 2: Utilisez des expressions régulières
Public Static Boolean IsNumeric (String STR) {Pattern Pattern = Pattern.Compile ("[0-9] *");Méthode 3: Utilisez le code ASCII
public static boolean isNumeric (String str) {for (int i = str.length (); - i> = 0;) {int chr = str.charat (i); return false;} return true;}J'espère que cet article sera utile à la programmation Java de tous.