
- Java.lang Package classes
- Java.lang - Home
- Java.lang - Boolean
- Java.lang - Byte
- Java.lang - Character
- Java.lang - Character.Subset
- Java.lang - Character.UnicodeBlock
- Java.lang - Class
- Java.lang - ClassLoader
- Java.lang - Compiler
- Java.lang - Double
- Java.lang - Enum
- Java.lang - Float
- Java.lang - InheritableThreadLocal
- Java.lang - Integer
- Java.lang - Long
- Java.lang - Math
- Java.lang - Number
- Java.lang - Object
- Java.lang - Package
- Java.lang - Process
- Java.lang - ProcessBuilder
- Java.lang - Runtime
- Java.lang - RuntimePermission
- Java.lang - SecurityManager
- Java.lang - Short
- Java.lang - StackTraceElement
- Java.lang - StrictMath
- Java.lang - String
- Java.lang - StringBuffer
- Java.lang - StringBuilder
- Java.lang - System
- Java.lang - Thread
- Java.lang - ThreadGroup
- Java.lang - ThreadLocal
- Java.lang - Throwable
- Java.lang - Void
- Java.lang Package extras
- Java.lang - Interfaces
- Java.lang - Errors
- Java.lang - Exceptions
- Java.lang Package Useful Resources
- Java.lang - Useful Resources
- Java.lang - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java.lang.Long.parseLong() Method
Description
The java.lang.Long.parseLong(String s, int radix) method parses the string argument s as a signed long in the radix specified by the second argument radix.Some examples can be seen here −
parseLong("0", 10) returns 0L parseLong("11", 10) returns 111L parseLong("-0", 10) returns 0L parseLong("-BB", 16) returns -187L parseLong("1010110", 2) returns 86L parseLong("ADMIN", 27) returns 5586836L parseLong("99", 8) throws a NumberFormatException
Declaration
Following is the declaration for java.lang.Long.parseLong() method
public static long parseLong(String s, int radix) throws NumberFormatException
Parameters
s − This is a String containing the long representation to be parsed.
radix − This is the radix to be used while parsing s.
Return Value
This method returns the long represented by the string argument in the specified radix.
Exception
NumberFormatException − if the string does not contain a parsable long.
Example
The following example shows the usage of java.lang.Long.parseLong() method.
package com.tutorialspoint; import java.lang.*; public class LongDemo { public static void main(String[] args) { // parses the string with specified radix long a = Long.parseLong("0", 10); System.out.println(a); long b = Long.parseLong("111", 10); System.out.println(b); long c = Long.parseLong("-0", 10); System.out.println(c); long d = Long.parseLong("-BB", 16); System.out.println(d); long e = Long.parseLong("1010110", 2); System.out.println(e); long f = Long.parseLong("2147483647", 10); System.out.println(f); long g = Long.parseLong("-2147483648", 10); System.out.println(g); long h = Long.parseLong("ADMIN", 27); System.out.println(h); } }
Let us compile and run the above program, this will produce the following result −
0 111 0 -187 86 2147483647 -2147483648 5586836
java_lang_long.htm
Advertisements