Core java
Wrapper Classe Introduction
Primitive Wrapper Classes
byte Byte
short Short
int Integer
long Long
float Float
double Double
char Character
boolean Boolean
Primitive to object -> boxing
Object to Primitive -> unboxing
Primitive to String
String to Primitive
Object to String
String to Object
Primitive to Object
public class PrimitiveAndObject {
public static void main(String[] args) {
int x = 100;
Integer y = Integer.valueOf(x);
int z = y.intValue();
}
}
Primitive to String
public class PrimitiveAndString {
public static void main(String[] args) {
byte x = 100;
String s = Byte.toString(x);
byte y = Byte.parseByte(s);
}
}
Object to String
public class ObjectAndString {
public static void main(String[] args) {
long x = 1000;
Long y = Long.valueOf(x);
String s = y.toString();
Long z = Long.valueOf(s);
}
}
Constructors
public class Constructors {
public static void main(String[] args) {
long l = 1000;
Long a = new Long(l);
String s ="2000";
Long b = new Long(s);
}
}
AllInOne
public class AllInOne {
public static void main(String[] args) {
int x = 100;
String y = Integer.toString(x);
Integer b = new Integer(y);
int z = b.intValue();
Integer c = new Integer(z);
String d = c.toString();
int e = Integer.parseInt(d);
}
}
Comments
Post a Comment