Java Utililty Methods Number Parse

List of utility methods to do Number Parse

  1. HOME
  2. Java
  3. N
  4. Number Parse

Description

The list of methods to do Number Parse are organized into topic(s).

Method

boolean isNumber(final String str)
Checks whether the provided string is a number.
if (isNullOrEmpty(str)) 
 return false;
final NumberFormat formatter = NumberFormat.getInstance();
final ParsePosition pos = new ParsePosition(0);
formatter.parse(str, pos);
return str.length() == pos.getIndex();
boolean isNumber(String str)
This method is used to check if the String passed is a number/integer only.
NumberFormat formatter = NumberFormat.getInstance();
ParsePosition pos = new ParsePosition(0);
formatter.parse(str, pos);
return str.length() == pos.getIndex();
boolean isNumeric(Class cls)
is Numeric
if (cls != null) {
 return cls == int.class || cls == long.class || cls == float.class || cls == double.class
 || Number.class.isAssignableFrom(cls);
return false;
boolean isNumeric(final String str)
is Numeric
final NumberFormat formatter = NumberFormat.getInstance();
final ParsePosition pos = new ParsePosition(0);
formatter.parse(str, pos);
return str.length() == pos.getIndex();
boolean isNumeric(String str)
Works out of a string could be parsed a Number
boolean isnumeric = false;
try {
 NumberFormat formatter = NumberFormat.getInstance();
 ParsePosition pos = new ParsePosition(0);
 formatter.parse(str, pos);
 isnumeric = (str.length() == pos.getIndex() ? true : false);
} catch (Exception e) {
 isnumeric = false;
...
boolean isNumeric(String str)
Returns true if the given string represents a parseable numeric value, either integer or floating point.
NumberFormat fmt = NumberFormat.getInstance();
ParsePosition pos = new ParsePosition(0);
fmt.parse(str, pos);
return str.length() == pos.getIndex();
boolean isNumeric(String str)
is Numeric
try {
 NUMFORMATTER.get().parse(str);
} catch (Exception e) {
 return false;
return true;
boolean isNumeric(String value, Locale locale)
Test, if a string contains a parsable number.
if (value == null)
 return false;
int start = 0;
final DecimalFormatSymbols symbols = (locale != null) ? DecimalFormatSymbols.getInstance(locale)
 : DecimalFormatSymbols.getInstance();
if (value.startsWith("+") || value.startsWith("-"))
 start++;
boolean fraction = false;
...
boolean isParsable(Object parser, String str)
is Parsable
Class theClass = (parser instanceof Class ? (Class) parser : parser.getClass());
boolean staticOnly = (parser == theClass), foundAtLeastOne = false;
Method[] methods = theClass.getMethods();
for (int index = 0; index < methods.length; index++) {
 Method method = methods[index];
 if (method.getName().startsWith("parse") && (!staticOnly || Modifier.isStatic(method.getModifiers()))
 && Modifier.isPublic(method.getModifiers()) && method.getGenericParameterTypes().length == 1
 && method.getGenericParameterTypes()[0] == String.class) {
...
int toNumber(char letter)
to Number
switch (letter) {
case ' ':
 return 0;
case 'a':
 return 1;
case 'b':
 return 2;
case 'c':
...


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