Casting and Data Type Conversion examples
String s = "56"; // no letters inside byte by = Byte.parseByte(s); //56 short sh = Short.parseShort(s); //56 int i = Integer.parseInt(s); //56 Integer i = Integer.valueOf(s); long lo = Long.parseLong(s); //56 float f = Float.parseFloat(s); //56.0 double d = Double.parseDouble(s); //56.0 char c = s.charAt(0); //5 boolean bo = Boolean.parseBoolean(s); //false
byte by = 1; short sh = 2; int i = 3; long lo = 4; float f = 5.6F; double d = 66.8F; char c = 's'; boolean bo = false; String s = by+""; // 1 String s = Byte.toString(by); String s = String.valueOf(by); // (i) ,(sh), (d) etc String s = Short.toString(sh); String s = Integer.toString(i); String s = Long.toString(lo); String s = Float.toString(f); // 5.6 String s = Double.toString(d); // 66.80000305175781 String s = Character.toString(c); // s String s = Boolean.toString(bo); // false
long x = (long)i; float ff = (float)5; double ff = (double)3.55; char ff = (char)3.55;