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

Java Long parseUnsignedLong(String s) Method

Java parseUnsignedLong(String s) method is the part of the Long class of the java.lang package. This method is used to parse the string value as an unsigned decimal Long object.

It must be noted that the characters passed in the string must be all decimal except for the first character which is used to define the sign of the integer. The ASCII plus '+' sign is used to depict a positive value.

Syntax:

public static long parseUnsignedLong(String s) throws NumberFormatException

Parameters:

The parameter passed is the string value whose unsigned decimal Long object is to be returned.

Returns:

Returns the unsigned decimal Long object of the string value passed as a parameter.

Example 1:

Here, two strings are passed and returned as their respective unsigned decimal Long objects.

import java.lang.Long;

public class StudyTonight 
{  
    public static void main(String[] args) 
    {     
        String s1 = "23"; 
        String s2 = "132";
        long n1 = Long.parseUnsignedLong(s1);  //converts the passed string as unsigned long
        long n2 = Long.parseUnsignedLong(s2);  //converts the passed string as unsigned long
        
        System.out.println("Equivalent Long object is : " + n1);
        System.out.println("Equivalent Long object is : " + n2);    
    }  
}


Equivalent Long object is : 23
Equivalent Long object is : 132

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.lang.Long;
import java.util.Scanner;

public class StudyTonight 
{  
    public static void main(String[] args) 
    {  
        try
        {
            System.out.println("Enter Value");
            Scanner sc = new Scanner(System.in);
            String s = sc.nextLine();
            long n = Long.parseUnsignedLong(s);  //converts the passed string as unsigned long

            System.out.println("Equivalent Long object is : " + n);
          }
        catch(Exception e)
        {
            System.out.println("Invalid Input!!");
        }
    }  
}


Enter Value
956
Equivalent Long object is : 956
***************************************
Enter Value
-577
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.