The following table lists the string representation of the values of the primitive data types.
The following table lists the string representation of the values of the primitive data types.
Data Type | Value | String Representation |
---|---|---|
int, short, | 1234 | "1234" |
byte, long | 0 | "0" |
char | 'A' | "A" |
char | '\u0041'(Unicode escape sequence) | "A" |
boolean | true | "true" |
boolean | false | "false" |
float | 2.5 | "2.5" |
float | 0.0F | "0.0" |
float | -0.0F | "-0.0" |
float | Float.POSITIVE_INFINITY | "Infinity" |
float | Float.NEGATIVE_INFINITY | "-Infinity" |
float | Float.NaN | "NaN" |
double | 12.34 | "12.34" |
double | 0.0 | "0.0" |
double | -0.0 | "-0.0" |
double | Double.POSITIVE_INFINITY | "Infinity" |
double | Double.NEGATIVE_INFINITY | "-Infinity" |
double | Double.NaN | "NaN" |
public class Main { public static void main(String[] args) { boolean b1 = true; boolean b2 = false; int num = 365; double d = -0.0; char c = 'A'; String str1; //from w w w. j a v a2 s .co m String str2 = null; str1 = b1 + " aaa"; System.out.println(str1); str1 = b2 + " bbb"; System.out.println(str1); str1 = str2 + " and void"; str1 = num + " days"; System.out.println(str1); str1 = d + " zero"; System.out.println(str1); str1 = Double.NaN + " is Double.NaN"; System.out.println(str1); str1 = c + " is a letter"; System.out.println(str1); str1 = "This is " + b1; System.out.println(str1); str1 = "Float.POSITIVE_INFINITY: " + Float.POSITIVE_INFINITY; System.out.println(str1); } }
If a String variable contains the null reference, the concatenation operator uses a string "null".
public class Main { public static void main(String[] args) { String str1 = "book2s.com"; String str2 = null; /*from ww w. j ava2 s .co m*/ String str3 = str1+ str2; System.out.println(str3); } }