Solved

String to int ?

Posted on 1998-02-16
1
558 Views
Last Modified: 2010-04-16
Hi, how can I convert a String to int ?. Example:

  String a = "2";
  String b = "3";
  int na = (value of String a to int);  //int na = 2;
  int nb = (value of String b to int);  //int nb = 3;
  System.out.println(" a + b = " + (na + nb));

Thanks.




 
 
0
Comment
Question by:Deladier
1 Comment
 
LVL 32

Accepted Solution

by:
jhance earned 10 total points
ID: 1233082
String a = "2";
String b = "3";

int sum;

try{
  Integer iA = Integer(a);
  Integer iB = Integer(b);
}
catch (NumberFormatException e){
  // Error...
}

sum = iA.intValue() + iB.intValue();
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now