Java Tutorial with Java Code Examples

Java Basics | String | Date | Collection | Java Map | Java Util | File I/O | XML | Threading | Network | i18n | Misc
Java Swing | JDBC | Servlet | JSP | JSTL | JMS | EJB | JPA | JSF | Struts | Spring | Hibernate
Web Services | Java PDF | JUnit | Ant | HTML | JavaScript | Apache | Tomcat | SQL | T-SQL | PL/SQL | MySQL

Java Basics

Introduction

Data Types and Arrays

Get User Input

Data Type Conversions

Control Flow

Handling Exception

 

  Java Basics » Data Type Conversions » Convert String to long

  Java Code Example:  StringToLongConverter.java  Download Sample Source Code

/*
 * Copyright © 2008 - 2009 it.ibluespace.com. All rights reserved.
 */
public class StringToLongConverter { public static void main(String args[]) { String str = "9876543210"; //approach 1: to convert String to long long l1 = Long.parseLong(str); System.out.println( "l1 = " + l1 ); //approach 2: to convert String to long long l2 = Long.valueOf(str); System.out.println( "l2 = " + l2 ); } }
 Download Source Code: StringToLongConverter.java

The command executed and output produced:


E:\JavaEECoding\>java StringToLongConverter
l1 = 9876543210
l2 = 9876543210

Search for Java code examples on this site

 
 

Resources

Java Tutorial

Java World

Java SE 6 API Doc


Terms of Use  |  License  Copyright 2008-2009 it.ibluespace.com. All rights reserved.  | 
All other trademarks are the property of their respective owners.