Dev/JAVA
JAVA 형변환 string to int, int to string
Aloner
2023. 4. 27. 18:21
728x90
반응형
String to Int
String 변수를 Integer 변수로 형변환 할 때는 Integer.valueOf()와 Integer.parseInf() 함수를 사용할 수 있습니다.
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
String str = "10";
System.out.println("str Type : " + (Integer.valueOf(str)).getClass().getName());
System.out.println("str : " + Integer.parseInt(str));
}
}
결과
str Type : java.lang.Integer
str : 10
반응형
Int to String
Integer 변수를 String 변수로 형변환 할 때는 Integer.toString() 함수와 String.valueOf() 함수를 사용합니다.
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
int x = 10;
System.out.println("x Type : " + Integer.toString(x).getClass().getName());
System.out.println("x Type : " + String.valueOf(x).getClass().getName());
}
}
결과
x Type : java.lang.String
x Type : java.lang.String
728x90
반응형