Casting integer to string in Java

Posted on 2011-03-16
Medium Priority
Last Modified: 2012-05-11
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?

Question by:Tolgar
  • 2
LVL 47

Assisted Solution

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

Accepted Solution

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

Expert Comment

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
LVL 92

Assisted Solution

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];

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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.

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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 tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

619 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