try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date date = sdf.parse("2021-07-28"); } catch (ParseException e) { System.err.println("Error parsing date: " + e.getMessage()); }
try { NumberFormat nf = NumberFormat.getInstance(); Number num = nf.parse("1234.56"); } catch (ParseException e) { System.err.println("Error parsing number: " + e.getMessage()); }These examples use classes from the java.text package, which is part of the Java SE library.