Converting an int to String using just one object

P

Prakash Prabhu

Hi,

Is it possible to convert a int value to String using less than 2 objects ?
Two ways of doing it are like :

1. String strValue = Integer.parseInt(value).toString() ;

2. String strValue = "" + value;

In each case two objects are used :

1. The Integer object , the final String object
2. The StringBuffer object , the final String object

Here "value" is an int variable

Are there any other methods ?

Please do excuse if this sounds like a dumb question, but I
would just like to know the best way of converting an int to String.


Thanks,
Prakash
 
M

Mike Wannamaker

Use

String strValue = String.valueOf(value);

which is same as calling

String strValue = Integer.toString(value);

--ekiM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top