How to Convert Double to String to Double in Java?

Java 8Object Oriented ProgrammingProgramming

Java lang package provides a Double class which has methods to convert Double to String and vice versa. You can convert a String to a double using the parseDouble() method and double to String using the toString() method

Example

Live Demo

public class StringDouble {
   public static void main(String args[]){
      Double data1 = 2.2;
      String str = Double.toString(data1);
      System.out.println(str);
      Double data2 = Double.parseDouble(str);
      System.out.println(data2);
   }
}

Output

2.2
2.2
raja
Published on 12-Feb-2018 08:58:39
Advertisements