How to convert string to (double, int or boolean) and int to String in Java

With this code, you can convert string to double or to int or to boolean and convert int to string in Java:

  1. Convert string to int:
    String aString = "78";
    int aInt = Integer.parseInt(aString);
  2. Convert string to double:
    String aString = "78";
    double aDouble = Double.parseDouble(aString);
  3. Convert string to boolean:
    String aString = "true";
    double aBoolean = Boolean.valueOf(aString);
  4. Convert int to string:
    int aInt = 1;    
    String aString = Integer.toString(aInt);
  5. Convert double to string:
    double aDouble = 1.0;    
    String aString = Double.toString(aDouble);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s