Javatpoint Logo
Javatpoint Logo

Java Integer toUnsignedString() Method

This method is used to get an unsigned String object representing the value of the Number Object. There is two different types of Java toUnsignedString() method which can be differentiated depending on its parameter.

These are:

  1. Java Integer toUnsignedString(int i) Method
  2. Java Integer toUnsignedString(int i, int radix) Method

1. Java Integer toUnsignedString(int i) Method

The toUnsignedString(int i) is an inbuilt method of Java which is used to return a string representation of the argument as an unsigned decimal value.

2. Java Integer toUnsignedString(int i, int radix) Method

This method returns a string representation of the first int type argument as an unsigned integer value in the radix specified by the second argument. If the radix is smaller than Character.MIN_RADIX or larger than Character.MAX_RADIX then the base 10 is used. In this method, the following ASCII characters are used as digits: 0 to 9 and a to z.

Note: Here, the first argument is treated as an unsigned value so, there is no leading sign character will be printed.

Syntax:

Following is the declarations of toUnsignedString() method:

Parameter:

DataType Parameter Description Required/Optional
int i It is an integer value specified by the user to be converted to an unsigned string. Required
int radix This is of integer type and used in the string representation. Required

Returns:

Method Returns
toUnsignedString(int i) It returns an unsigned string representation of the int type argument in base 10.
toUnsignedString(int i, int radix) It returns an unsigned string representation of the int type argument in the specified radix.

Exceptions:

NA

Compatibility Version:

Java 1.8 and above

Example 1

Test it Now

Output:

String Representation = 25
String Representation = 4294967278

Example 2

Output:

Enter Value: ABCD
Exception in thread "main" java.util.InputMismatchException
	at java.base/java.util.Scanner.throwFor(Scanner.java:939)
	at java.base/java.util.Scanner.next(Scanner.java:1594)
	at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
	at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
	at myPackage.IntegerToUnsignedStringExample2.main(IntegerToUnsignedStringExample2.java:9)

Example 3

Test it Now

Output:

String Value = 4294967231
String Value = 41
String Value = ffffffbf
String Value = 1000001
String Value = 11111111111111111111111110111111

Example 4

Output:

Enter Number: -37245327
Enter Radix/Base: 16
Output: fdc7ae71





Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA