Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 470
  • Last Modified:

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,
0
Tolgar
Asked:
Tolgar
  • 2
3 Solutions
 
for_yanCommented:
You just sya String str = "" + list[j];
0
 
Gurvinder Pal SinghCommented:
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
 
objectsCommented:
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

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now