JAVA String to Integer & String to Double and opposite!

Beispiel - Java convert String to Integer & ConvertIntToString



public class ConvertIntToString {
  public static void main(String[] args) {

    int aInt = 1;

    String aString = Integer.toString(aInt);

  }
}



public class ConvertStringToInt {
  public static void main(String[] args) {
    String aString = "78";
    int aInt = Integer.parseInt(aString);

    System.out.println(aInt);
  }
}


Java String to Double & Double.toString



String myString = Double.toString(aDouble);


double aDouble = Double.parseDouble(aString);


Java Example: Converting boolean to String

Einfach boolean convertierung zu String mit der Wrapperklasse. Wandlung (boxing/unboxing) des Ordinaltyp boolean mit Hilfe der Wrapperklasse Boolean



String myString = Boolean.toString(boovar2);



public class BooleanToString {
    public static void main(String[] args) {

        /* Method 1: using valueOf() method
         * of String class.
         */
        boolean boovar = true;
        String str = String.valueOf(boovar);
        System.out.println("String is: "+str);

        /* Method 2: using toString() method
         * of Boolean class
         */
        boolean boovar2 = false;
        String str2 = Boolean.toString(boovar2);
        System.out.println("String2 is: "+str2);
    }
}



Comments

No comments yet.

Add Comment

* Required information
(never displayed)
 
Bold Italic Underline Strike Superscript Subscript Code PHP Quote Line Bullet Numeric Link Email Image Video
 
Smile Sad Huh Laugh Mad Tongue Crying Grin Wink Scared Cool Sleep Blush Unsure Shocked
 
1000
Enter the last letter of the word satellite.
 
Enter answer:
Captcha
Refresh
 
Enter code:
 
Notify me of new comments via email.
 
Remember my form inputs on this computer.
 
I have read and understand the privacy policy. *
 
I have read and agree to the terms and conditions. *
 
 
Powered by Commentics