Showing posts with label Interger type casting in java. Show all posts
Showing posts with label Interger type casting in java. Show all posts

Tuesday, 18 June 2013

Java typecast and conversion of one data type to another

                                     Java Data Type Casting

                                          Integer

 int a=10;
Int to String    --        String b=a+””;  or  b=a.toString();
 Int to char      –        Char b=(char)a;
 int to long      --        long b=Long.valueOf(a);
int to double   --        double b=a;
int to float       --        float b=a;

                                         String

String a="harsh";
int index=1

String to char -- char b=a.charAt(index);
String to int --       int b=Integer.parseInt("10");
String to long --   long b=Integer.parseInt("10");
String to double--   double b=Float.parseFloat("10.00");
String to float--   float b=Float.parseFloat("10.00");