java.lang.Integer의 toString() 메서드는 문자열 객체를 반환합니다. Integer 클래스에는 3개의 toString() 메서드가 있습니다. 하나씩 살펴보시죠 -
문자열 toString()
예시
java.lang.Integer.toString() 메소드는 이 Integer의 값을 나타내는 String 객체를 반환합니다. 이제 예를 살펴보겠습니다 -
import java.lang.*;
public class Demo {
public static void main(String[] args) {
Integer i = new Integer(20);
// returns a string representation of the integer value in base 10
String retval = i.toString();
System.out.println("Value = " + retval);
}
} 출력
Value = 20
정적 문자열 toString(int i)
java.lang.Integer.toString(int i) 메소드는 지정된 정수를 나타내는 String 객체를 반환합니다. 여기서 i는 변환할 정수입니다.
예시
이제 예를 살펴보겠습니다 -
import java.lang.*;
public class Demo {
public static void main(String[] args) {
Integer i = new Integer(10);
// returns a string representation of the specified integer in base 10
String retval = i.toString(30);
System.out.println("Value = " + retval);
}
} 출력
Value = 30
정적 문자열 toString(int i, int 기수)
java.lang.Integer.toString(int i, int radix) 메서드는 두 번째 인수 radix에 의해 지정된 기수에서 첫 번째 인수 i의 문자열 표현을 반환합니다. 기수가 Character.MIN_RADIX보다 작거나 Character.MAX_RADIX보다 큰 경우 , 기수 10이 대신 사용됩니다.
여기서 i는 변환할 정수이고 radix는 문자열 표현에 사용할 기수입니다.
예시
이제 예를 살펴보겠습니다 -
import java.lang.*;
public class Demo {
public static void main(String[] args) {
Integer i = new Integer(10);
// returns a string representation of the specified integer with radix 10
String retval = i.toString(30, 10);
System.out.println("Value = " + retval);
// returns a string representation of the specified integer with radix 16
retval = i.toString(30, 16);
System.out.println("Value = " + retval);
// returns a string representation of the specified integer with radix 8
retval = i.toString(30, 8);
System.out.println("Value = " + retval);
}
} 출력
Value = 30 Value = 1e Value = 36