String to Double in Java In this lecture we will see the String to Double conversion. There are three ways to convert a String into a double. 1: Using Double.parseDouble public static double parseDouble ( String str ) throws NumberFormatException It returns the double value represented by the string argument and throws following exceptions: NullPointerException – if the specified String str is null. NumberFormatException – if the string format is not valid. For example If the string is “122.20ab” this exception will be thrown. String strg = "222.102" ; Double var = Double . parseDouble ( str ); Double variable var value would be 222.102 after conversion. 2: Using Double.valueOf String strg1 = "222.102" ; Double var1 = Double . valueOf ( strg1 ); The value of var1 would be 222.102 3: Double class constructor String strg2 = "222.102" ; Double var2 = new Double ( strg2 ); Double class has a constru
IF YOU CAN DREAM IT. YOU CAN ACHIEVE IT.