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 int

  Java Code Example:  StringToIntConverter.java  Download Sample Source Code

/*
 * Copyright © 2008 JavaEECoding.com. All rights reserved.
 */
public class StringToIntConverter { public static void main(String args[]) { String str = "598"; //approach 1: to convert String to int int int1 = Integer.parseInt(str); System.out.println( "int1 = " + int1 ); //approach 2: to convert String to int int int2 = Integer.valueOf(str); System.out.println( "int2 = " + int2 ); } }
 Download Source Code: StringToIntConverter.java

The command executed and output produced:


E:\JavaEECoding\>java StringToIntConverter
int1 = 598
int2 = 598

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 JavaEECoding.com. All rights reserved.  |  Chinese Version
All other trademarks are the property of their respective owners.