class ConvTest {
public static void main(String[] args) {
//String --> Primitive type
String sd = new String("1.23");
double d = Double.parseDouble(sd);
System.out.println("Double.parseDouble(d) : " + d);
String si = new String("123");
int i = Integer.parseInt(si);
System.out.println("Integer.parseInt(si) : " + i);
//String --> Wrapper
String sd1 = new String("1.24");
Double d1 = new Double(sd1);
System.out.println("new Double(sd1) : " + d1);
String si1 = new String("123");
Integer i1 = new Integer(si1);
System.out.println("new Integer(si1) : " + i1);
//Wrapper --> String
String s1 = i1.toString();
String s2 = d1.toString();
String s3 = String.valueOf(i1);
String s4 = String.valueOf(d1);
System.out.println("s1, s3 : " +s1 + ", " + s3);
System.out.println("s2, s4 : " +s2 + ", " + s4);
}
}
댓글 없음:
댓글 쓰기