Solved

Casting integer to string in Java

Posted on 2011-03-16
4
452 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
  • 2
4 Comments
 
LVL 47

Assisted Solution

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

Accepted Solution

by:
gurvinder372 earned 200 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 150 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

948 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now