Casting integer to string in Java

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,
TolgarAsked:
Who is Participating?
 
Gurvinder Pal SinghConnect With a Mentor Commented:
0
 
for_yanConnect With a Mentor Commented:
You just sya String str = "" + list[j];
0
 
for_yanCommented:

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
 
objectsConnect With a Mentor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.