Skip to content
Fix Code Error

How to convert String to long in Java?

March 13, 2021 by Code Error
Posted By: Anonymous

I got a simple question in Java: How can I convert a String that was obtained by Long.toString() to long?

Solution

Use Long.parseLong()

 Long.parseLong("0", 10)        // returns 0L
 Long.parseLong("473", 10)      // returns 473L
 Long.parseLong("-0", 10)       // returns 0L
 Long.parseLong("-FF", 16)      // returns -255L
 Long.parseLong("1100110", 2)   // returns 102L
 Long.parseLong("99", 8)        // throws a NumberFormatException
 Long.parseLong("Hazelnut", 10) // throws a NumberFormatException
 Long.parseLong("Hazelnut", 36) // returns 1356099454469L
 Long.parseLong("999")          // returns 999L
Answered By: Anonymous

Related Articles

  • How can I resolve Web Component Testing error?
  • TLS 1.3 server socket with Java 11 and self-signed…
  • Unable to run Robolectric and Espresso with a…
  • Regex needed to match a proper currency format of…
  • When I'm testing a web app by JUnit and Mockito I…
  • ClassNotFoundException:…
  • Eclipse will not start and I haven't changed anything
  • How to convert number to words in java
  • JUNIT @ParameterizedTest , Parameter resolution Exception
  • Neither BindingResult nor plain target object for…
  • java IO Exception: Stream Closed
  • Jetpack Compose and Hilt Conflict
  • SQLException: No suitable Driver Found for…
  • Processing 2D Array into a List of Lists in Python
  • Gradle error: Execution failed for task…
  • SecurityException: Permission denied (missing…
  • Examples of GoF Design Patterns in Java's core libraries
  • Launching Spring application Address already in use
  • Requested bean is currently in creation: Is there an…
  • Can't access Eclipse marketplace
  • Javax.net.ssl.SSLHandshakeException:…
  • Using enums in a spring entity
  • Execution failed for task…
  • android studio 0.4.2: Gradle project sync failed error
  • org.gradle.api.tasks.TaskExecutionException:…
  • How to parse JSON file with Spring
  • Android- Error:Execution failed for task…
  • How do I print my Java object without getting…
  • Mock MQRFH2 header in JUnit Testing Error [MQRFH2…
  • How to convert java.util.Date to java.sql.Date?
  • Android Studio 4.2.1 NullPointer Exception on startup
  • Can't install via pip because of egg_info error
  • Configure hibernate to connect to database via JNDI…
  • JPA Hibernate Persistence exception…
  • Could not install Gradle distribution from…
  • Vaadin Spring Boot - There was an exception while…
  • ClassNotFoundException thrown
  • How to obtain the start time and end time of a day?
  • How can I prevent java.lang.NumberFormatException:…
  • Getting Dropwizard Client And Jersey/HTTP I/O Error…
  • How can I throw CHECKED exceptions from inside Java…
  • Convert Java Date to UTC String
  • Jetty server throws idle timeout for REST calls
  • Error inflating class android.support.v7.widget.Toolbar?
  • java.lang.ClassNotFoundException: HttpServletRequest
  • Eclipse fails to open .vue files in Web Page Editor
  • What is a stack trace, and how can I use it to debug…
  • How to unescape a Java string literal in Java?
  • "Non-resolvable parent POM: Could not transfer…
  • How do I install Java on Mac OSX allowing version switching?
  • Fetch content from API with Retrofit and Kotlin
  • How to add Typescript to a Nativescript-Vue project?
  • Java ElasticSearch None of the configured nodes are…
  • UnsatisfiedDependencyException: Error creating bean…
  • String concatenation with Groovy
  • What is the difference between `Enum.name()` and…
  • java.lang.RuntimeException: Unable to instantiate…
  • Problems using Maven and SSL behind proxy
  • Issue adding access token to header in Backbone: It…
  • Convert hex string to int
  • Plugin…
  • Spring Boot - Cannot determine embedded database…
  • Spring Boot with ElasticSearch in Groovy: WebClient…
  • MatchIt combined with lapply(): Error in…
  • Spring Security exclude url patterns in security…
  • Gradle: Execution failed for task ':processDebugManifest'
  • Make Vuetify rule for number between 0 and 999 or no input
  • RxJava Main Thread Always Crash
  • org.springframework.beans.factory.NoSuchBeanDefiniti…
  • What's the difference between Instant and LocalDateTime?
  • Address already in use: JVM_Bind
  • Multiple paired permutation t-tests using perm.t.test
  • Injection of autowired dependencies failed;
  • Spring schemaLocation fails when there is no…
  • Multipart File Upload Using Spring Rest Template +…
  • Eclipse - Run in Debug Mode fails
  • How to disable SSL certificate checking with Spring…
  • Python: split a list based on a condition?
  • NullpointerException error while working with…
  • What's causing my java.net.SocketException:…
  • multiple login routes using ember-cli-simple-auth
  • Failed to execute goal…
  • Jackson cannot parse body of a POST request
  • Regular expression to match numbers with or without…
  • Why does Spring security throw exception…
  • IOException: read failed, socket might closed -…
  • Submit the value without the mask in PrimeFaces component
  • java.net.UnknownHostException: Unable to resolve…
  • Integer.valueOf() vs. Integer.parseInt()
  • Java.lang.NoClassDefFoundError:…
  • Name [jdbc/mydb] is not bound in this Context
  • Exception : AAPT2 error: check logs for details
  • Understanding checked vs unchecked exceptions in Java
  • How to apply a CSS class on hover to dynamically…
  • Error cannot convert a DBNULL object to other C#…
  • java.lang.NoClassDefFoundError:…
  • Find out free space on tablespace
  • Java - Regex, nested recursion match
  • Filtering DataGridView without changing datasource
  • Convert System.Drawing.Color to RGB and Hex Value

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Using Python 3 in virtualenv

Next Post:

SQL update query using joins

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error