Java Long parseUnsignedLong(String s, int radix) method example

HQ » Java Tutorial » java.lang » Long » parseUnsignedLong(String s, int radix)
Java Long parseUnsignedLong(String s, int radix) method example 2018-02-16T07:26:12+00:00

java.lang.Long parseUnsignedLong(String s, int radix)

Description

The Long.parseUnsignedLong(String s, int radix) java method

Parses the string argument as an unsigned long in the radix specified by the second argument. An unsigned integer maps the values usually associated with negative numbers to positive numbers larger than MAX_VALUE. The characters in the string must all be digits of the specified radix (as determined by whether Character.digit(char, int) returns a nonnegative value), except that the first character may be an ASCII plus sign ‘+’ (‘\u002B’). The resulting integer value is returned.

An exception of type NumberFormatException is thrown if any of the following situations occurs:

  • The first argument is null or is a string of length zero.
  • The radix is either smaller than Character.MIN_RADIX or larger than Character.MAX_RADIX.
  • Any character of the string is not a digit of the specified radix, except that the first character may be a plus sign ‘+’ (‘\u002B’) provided that the string is longer than length 1.
  • The value represented by the string is larger than the largest unsigned long, 2^64-1.

Make a note that the parseUnsignedLong() method of Long class is static thus it should be accessed statically which means the we would be calling this method in this format:

Long.parseUnsignedLong(method args)

Non static method is usually called by just declaring method_name(argument) however in this case since the method is static, it should be called by appending the class name as suffix. We will be encountering a compilation problem if we call the java parseUnsignedLong method non statically.

Method Syntax

public static int parseUnsignedLong(String s, int radix)

Method Argument

Data Type Parameter Description
String s the String containing the unsigned integer representation to be parsed
int radix the radix to be used while parsing s.

Method Returns

The parseUnsignedLong(String s, int radix) method of Long class returns the unsigned long represented by the string argument in the specified radix.

Compatibility

Requires Java 1.8 and up

Java Long parseUnsignedLong(String s, int radix) Example

Below is a simple java example on the usage of parseUnsignedLong(String s, int radix) method of Long class.

Sample Output

Below is the sample output when you run the above example.

Java Long parseUnsignedLong(String s, int radix) example output

Suggested Reading List

Contact Info

Singapore

Our Goal

JavaTutorialHQ aims to to be The Ultimate Guide on Java with hundreds of examples from basic to advance Topics.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close