문자열 숫자 변환 (String to Int, Int to String)

총콩팡잉·2023년 4월 5일
0
post-thumbnail

📘 String -> int

문자열을 숫자로 변환

  • Integer.parseInt()
  • Integer.valuseOf()
public class StringToInt {
	public static void main(String[]args) {
    	String s1 = "100";
        String s2 = "200";
        
        int i1 = Integer.parseInt(s1);
        int i2 = Integer.valueOf(s2);
        
        System.out.println(i1); //100
        System.out.println(i2); //200
    }
}

📘 int -> String

숫자를 문자열로 변환

  • Integer.toString
  • String.valueOf()
public class IntToString {
	public static void main(String[]args) {
    	int i1 = 100;
        int i2 = 200;
        
        String s1 = Integer.toString(i1);
        String s2 = String.valueOf(i2);
        
        System.out.println(s1); //100
        System.out.println(s2); //200
    }
}
profile
Back-end 마스터가 되는 그날까지

0개의 댓글