Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b5fc947

Browse files
Update 2023年12月07日-check-if-string-is-a-number-or-not.md
1 parent 18bcc5b commit b5fc947

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

‎_posts/java-programs/2023-12-07-check-if-string-is-a-number-or-not.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ title: "Java Program To Check If the given String Is A Number or Not"
44
author: gaurav
55
categories: [Java Programs, Core Java]
66
toc: true
7-
description: "In this tutorial, we will see a Java program to check if the given String is number or not."
7+
description: "In this tutorial, we will see a Java program to check if the given String is a number or not."
88
---
99

10-
In this tutorial, we will see a Java program to check if the given String is number or not.
10+
In this tutorial, we will see a Java program to check if the given String is a number or not.
1111

1212
We can check it using the regex expression.
1313

1414
## Java Program To Check If the Given String is Number or Not Using Regex Expression
1515

16-
In the below program we have simply used the regex expression to check whether the given string is numeric or not.
16+
In the below program, we have simply used the regex expression to check whether the given string is numeric or not.
1717

1818
The regex expression to check this is `-?\\d+`
1919

@@ -29,7 +29,7 @@ Here,
2929
import java.util.List;
3030

3131
/**
32-
* A Java program to check if the given String is number of not.
32+
* A Java program to check if the given String is a number or not.
3333
* @author coderolls.com
3434
*/
3535
public class CheckIfNumber {
@@ -48,8 +48,8 @@ public class CheckIfNumber {
4848
}
4949

5050
/**
51-
* A method check if the input param string is a numeric or not
52-
* it is uses a regex Expression
51+
* A method checks if the input param string is numeric or not
52+
* It uses a regex Expression
5353
* -? --> negative sign, could have none or one
5454
* \\d+ --> one or more digits
5555
* @param str
@@ -76,15 +76,15 @@ The String 'Google' is not a Number.
7676

7777
## Java Program To Check If the Given String is Number or Not Using the `Character.isDigit()` method
7878

79-
In this method we are iterating over an array of characters of the String and checking if any character is a digit or not.
79+
In this method, we are iterating over an array of characters of the String and checking if any character is a digit or not.
8080

81-
If we found one or more digit in the string, the given string is not a number string or a number.
81+
If we find one or more digits in the string, the given string is not a number string or a number.
8282

8383
```Java
8484
import java.util.List;
8585

8686
/**
87-
* A Java program to check if the given String is number of not.
87+
* A Java program to check if the given String is a number or not.
8888
* using the Character.isDigit() method.
8989
* @author coderolls.com
9090
*/
@@ -104,8 +104,8 @@ public class CheckIfNumber2 {
104104
}
105105

106106
/**
107-
* A method check if the input param string is a numeric or not
108-
* it is uses a regex Expression
107+
* A method checks if the input param string is numeric or not
108+
* It uses a regex Expression
109109
* -? --> negative sign, could have none or one
110110
* \\d+ --> one or more digits
111111
* @param str
@@ -124,7 +124,7 @@ public class CheckIfNumber2 {
124124
return false;
125125
}
126126
}
127-
//If not a single ch is digit, the string is numeric
127+
//If not a single ch is a digit, the string is numeric
128128
return true;
129129
}
130130
}
@@ -169,4 +169,4 @@ public static boolean isInteger(String s) {
169169
}
170170
```
171171

172-
**But this way is not recommended as it causes expensive exception in the code.**
172+
**But this way is not recommended as it causes expensive exceptions in the code.**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /