public class StringToOther { public static void main(String[] args) { // ===================== String to Int int i = Integer.parseInt("55"); System.out.println("Integer.parseInt(\"55\") : "+i); int j = Integer.valueOf("56"); System.out.println(" Integer.valueOf(\"56\") : "+j); // ================== String to Double Double d1 = Double.parseDouble("55.69"); System.out.println(" Double.parseDouble(\"55.69\") : "+d1); // ================== String to float Float f1 = Float.parseFloat("55.69"); System.out.println(" Float.parseFloat(\"55.69\") : "+f1); // OR float f2 = (Float.valueOf("600.55")).floatValue(); System.out.println(" (Float.valueOf(\"600.55\")).floatValue() : "+f2); // ================== String to Date String sDate1 = "31/12/1992"; try { Date date1 = new SimpleDateFormat("dd/MM/yyyy").parse(sDate1); System.out.println(" new SimpleDateFormat(\"dd/MM/yyyy\").parse(sDate1) : "+date1); } catch (ParseException e) { e.printStackTrace(); } } }
Tuesday, 14 February 2017
Conversion : StringToOther
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment