Here you can find the source of toLongValue(final String candidateString)
Parses the given candidate string into a Long .
Parameter | Description |
---|---|
candidateString | The string to parse. |
Parameter | Description |
---|---|
NumberFormatException | If unable to parse the given string. |
public static Long toLongValue(final String candidateString)
//package com.java2s; //License from project: Open Source License public class Main { /**// ww w . ja v a 2 s. com * <p> * Parses the given candidate string into a {@link Long}. * </p> * * @param candidateString * The string to parse. * @return A {@link Long} representing the given string, assuming that it is * actually a valid long. * @throws NumberFormatException * If unable to parse the given string. */ public static Long toLongValue(final String candidateString) { Long result; if (candidateString == null || candidateString.length() == 0) throw new NumberFormatException("Cannot parse zero length string."); // remove qualifier first String longTxtVal = candidateString; if (longTxtVal.length() > 2 && (longTxtVal.endsWith("l") || longTxtVal.endsWith("L"))) longTxtVal = longTxtVal.substring(0, longTxtVal.length() - 1); result = new Long(longTxtVal); return result; } }