how can i convert int to char or string

now les say: i want to convert int to char
ex:
int a = 3
char b = '3'
note they both are same number

or int to String
int a = 35;
String c = "35";

note i already tried

b = (char)a; but failed. it print weird symbol

you can try this

from int to string

int a=3;
String s=a+"":

from int to char

char c = (char)(((int)'0')+a);

however here the value of 'a' should be a single digit number

Comments
good solution

The right way to convert an int to a char is using the Character.forDigit method.

char b = Character.forDigit(a,10);
Comments
really new thing i get to learn...

you can convert it in different way like:

1) built-in convert

int a1 = 5;
String s = ""+a1;

2) integer convert

int a2 = 5;
String s2 = Integer.toString(a2);

3) format convert

int a3 = 9;
String s3 =String.format("%d", a3);

Also one possible solution is:

StringBuilder sb = new StringBuilder();
sb.append("");
sb.append(i);
String strI = sb.toString();

or simply

Integer i;
String s = i.toString();

or

int aInt = 1;
String aString = Integer.toString(aInt);
Comments
Best and most complete answer

One more thing is:
In-fact String.valueOf() method is overloaded to accept almost all primitive type so you can use it convert char, double, float or any other data type into String. Static binding is used to call corresponding method in Java. Here is an example of int to String using String.valueOf().

String price = String.valueOf(123);

instead of 123 you can also pass int variable

This article has been dead for over six months. Start a new discussion instead.