New Tutorials:   NUMPY    TKINTER    KOTLIN    JAVASCRIPT    SASS/SCSS    PL/SQL    Matplotlib    C++ Programs

Java Integer toUnsignedString() Method

Java toUnsignedString() method is a part of the Integer class of the java.lang package. This method returns the equivalent String object of the integer value passed as an argument as an unsigned decimal value.

In short, this method is used to convert integer value into an unsigned String.

Syntax:

public static String toUnsignedString(int i)  

Parameter:

The parameter passed is the integer value whose String representation of the unsigned decimal value is to be returned.

Returns:

Returns the unsigned base 10 equivalent of the long value passed as a parameter as a String.

Example 1:

Here, the integer values are converted into its equivalent unsigned decimal values and represented as Strings.

import java.lang.Integer;

public class StudyTonight
{  
    public static void main(String[] args)
      {  
        int a = 40;
        int b = -56;
        System.out.println("Equivalent String is : "+Integer.toUnsignedString(a));  //returns the unsigned String of the integer value 
        System.out.println("Equivalent String is : "+Integer.toUnsignedString(b));  //returns the unsigned String of the integer value 
      }  
}  


Equivalent String is : 40
Equivalent String is : 4294967240

Example 2:

Here is a user-defined example where anyone using this code can put a value of his choice and get the equivalent output.

import java.util.Scanner;  

public class StudyTonight
{  
     public static void main(String[] args) 
       {  
          try
           {
             System.out.print("Enter the value ");  
             Scanner sc = new Scanner(System.in);  
             int val = sc.nextInt();  
             String s = Integer.toUnsignedString(val); //converting to unsigned string
             System.out.println("String value is : "+ s);  
         
           }
         catch(Exception e)
           {
           System.out.println("Invalid input!!");
           }
      
        }  
}  


Enter the value 85
String value is : 85
***********************
Enter the value -69
String value is : 4294967227
*************************
Enter the value 0x71
Invalid input!!

Live Example:

Here, you can test the live code example. You can execute the example for different values, even can edit and write your examples to test the Java code.