Logo

Programming-Idioms

History of Idiom 137 > diff from v4 to v5

Edit summary for version 5 by programming-idioms.org:
[Java] Kerning

Version 4

2016-06-10, 21:46:01

Version 5

2016-06-10, 21:46:29

Idiom #137 Check if string contains only digits

Set boolean b to true if string s contains only characters in range '0'..'9', false otherwise.

Idiom #137 Check if string contains only digits

Set boolean b to true if string s contains only characters in range '0'..'9', false otherwise.

Code
boolean b = s.matches("[0-9]*");
Code
boolean b = s.matches("[0-9]*");
Comments bubble
This uses a regular expression .
Comments bubble
This uses a regular expression.
Doc URL
https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#matches-java.lang.String-
Doc URL
https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#matches-java.lang.String-
Origin
http://stackoverflow.com/a/10575676/871134
Origin
http://stackoverflow.com/a/10575676/871134
Demo URL
https://ideone.com/xtfb5B
Demo URL
https://ideone.com/xtfb5B