?
Solved

Casting integer to string in Java

Posted on 2011-03-16
4
Medium Priority
?
461 Views
Last Modified: 2012-05-11
Hi,
I have the following line in my code:

java.lang.String str = java.lang.Integer.parseInt(list[j]);

Open in new window


list has integers in it. However I want str to be string because I will feed it to a function and it requires string input.

How can I cast this integer to string safely?

Thanks,
0
Comment
Question by:Tolgar
[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
  • 2
4 Comments
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 600 total points
ID: 35153739
You just sya String str = "" + list[j];
0
 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 800 total points
ID: 35153740
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35153744

if list[j] is an integer
then when you contcatenate it with empty string it becomes
equialent string

that's why
String str = "" + list[j];
will give you what you want
0
 
LVL 92

Assisted Solution

by:objects
objects earned 600 total points
ID: 35153774
you can convert the int to a string, but you've already got the string so not really necessary as you can do the following

java.lang.String str = list[j];
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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 will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month13 days, 3 hours left to enroll

777 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