Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Casting from integer to string?

Status
Not open for further replies.

javaken

Technical User
May 15, 2004
20
BE
In Vb.net = DirectCast .....

In Java ?

Thanks!!! [smile]
 
String str = (String) intVariable;

-kaht

banghead.gif
 
hi
if i don't missunderstand you

Code:
String yourString = "" + yourInt; //just simple :))

 
kaht :

You cannot do this :

Code:
		Integer a = new Integer(1);
		String s = (String)a;
because these two objects cannot be cast against each other because they are not related.
Nor can you do this :

Code:
		int a = new 1;
		String s = (String)a;

because you cannot cast from a primitive to an Object.

fuadhamidov's suggestion is the simplest.
 
String yourString = Integer.toString(int); <p>Liam Morley<br><A HREF="mailto:"></A><br>&quot;light the deep, and bring silence to the world.<br>light the world, and bring depth to the silence.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top