Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to Integer to a string

Posted on 2004-03-25
11
Medium Priority
?
228 Views
Last Modified: 2010-03-31
I Sorry for this quiestion but i dont have idea of how to do this
how can i convert a string to a integer
Felipe
0
Comment
Question by:Felipe1976
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +3
11 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 10684062
int x = Integer.parseInt("12345");
0
 
LVL 1

Accepted Solution

by:
dentrita earned 400 total points
ID: 10684085
toString
public String toString()
Returns a String object representing this Integer's value. The value is converted to signed decimal representation and returned as a string, exactly as if the integer value were given as an argument to the toString(int) method.

Overrides:
toString in class Object
Returns:
a string representation of the value of this object in base 10.

or can try


Integer.parseInt(x) converts String to int.
0
 
LVL 92

Expert Comment

by:objects
ID: 10684101
int i = 20;
String s = Integer.toString(i);
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:Mayank S
ID: 10684349
objects....

>> convert a string to a integer

String s = Integer.toString(i)  ??? Perhaps typed that a little too fast ;-) ?

Anyway, you can also use: int i = new Integer ( stringObject ).intValue (). However, it might be better to use Integer.parseInt ( stringObject ) as it is useless to instantiate an extra object.
0
 

Expert Comment

by:pradeepbkumar
ID: 10684514
U can use the following example...

String str = "10";
int strValue = Integer.parseInt(str).intValue();

which would give the value 10 into the variable strValue.

Regards,
Pradeep
0
 
LVL 92

Expert Comment

by:objects
ID: 10684556
> String s = Integer.toString(i)  ??? Perhaps typed that a little too fast ;-) ?

Not really.
Perhaps Felipe1976 typed the question too fast :)

Q. "How to Integer to a string"
0
 

Expert Comment

by:pradeepbkumar
ID: 10684584
Is the question for Converting a string to an integer or the other way???

Regards,
Pradeep
0
 

Expert Comment

by:sharmapradeepk
ID: 10684603
String str1 = "101";
int intVal = Integer.parseInt(str1);


0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10684632
>> int strValue = Integer.parseInt(str).intValue();

No. Integer.parseInt () is enough. You cannot do an intValue () over a result from parseInt () because parseInt () returns a simple 'int and not an Integer object. Or else you can do: new Integer ( str ).intValue () -> but like I said, its a useless instantiation of an extra object.
0
 

Expert Comment

by:pradeepbkumar
ID: 10684647
Ok
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10713681
Felipe1976,

We still don't know if you were trying to convert a String to an integer or an integer to a String?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.

719 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