Java Long Number From toLongValue(final String candidateString)

Here you can find the source of toLongValue(final String candidateString)

Description

Parses the given candidate string into a Long .

License

Open Source License

Parameter

Parameter Description
candidateString The string to parse.

Exception

Parameter Description
NumberFormatException If unable to parse the given string.

Return

A representing the given string, assuming that it is actually a valid long.

Declaration

public static Long toLongValue(final String candidateString) 

Method Source Code

//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;
    }
}

Related

  1. toLongTime()
  2. toLongTimestamp(Object cell)
  3. toLongUnsigned(int intValue)
  4. toLongValue(byte... bytes)
  5. toLongValue(final Object o)
  6. toLongValue(Object value)