Thursday, February 12, 2015

to String

It is possible to convert primitive data types to string with the aid of toString. Lets view this with an example.

public class ToStringProgram{

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  
  int x=100,y=200;
  String z=Integer.toString(x);
  String l=Integer.toString(y);
  System.out.println(z+l);

 }
}


We have two int variables defined which is x and y, next we convert to string and store it in there respective variables z and l. If we perform a concat operation on these variable it is output is a string. Similarly we can perform on float, double,long but not on char and boolean. >>>ParseInt,ParseFloat
------------------------------------------------------------------------------------------------------------