ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Integer.parseInt(CharSequence s, int beginIndex, int endIndex, int radix)
    공부 2026. 3. 2. 14:00

    @java. lang. Integer
    public static int parseInt(     @NotNull  CharSequence s,
        int beginIndex,
        int endIndex,
        int radix )
    throws NumberFormatException
    Parses the CharSequence argument as a signed int in the specified radix, beginning at the specified beginIndex and extending to endIndex - 1.
    The method does not take steps to guard against the CharSequence being mutated while parsing.
    Params:
    s – the CharSequence containing the int representation to be parsed beginIndex – the beginning index, inclusive. endIndex – the ending index, exclusive. radix – the radix to be used while parsing s.
    Returns:
    the signed int represented by the subsequence in the specified radix.
    Throws:
    NullPointerException – if s is null.
    IndexOutOfBoundsException – if beginIndex is negative, or if beginIndex is greater than endIndex or if endIndex is greater than s. length().
    NumberFormatException – if the CharSequence does not contain a parsable int in the specified radix, or if radix is either smaller than Character. MIN_RADIX or larger than Character. MAX_RADIX.
    Since:
    9

     

     

     

    radix = 진법

    몇 진수로 해석할 거냐

     

     

     

    CharSequence 는 “문자열 계열 인터페이스”

    CharSequence는 인터페이스.
    “문자처럼 나열된 것”이면 구현할 수 있음.

    대표 구현체들:

    • String
    • StringBuilder
    • StringBuffer
    • CharBuffer

    char[] 다루려다가 발견 😅

     

     

     

     

    Java 9부터 추가된 오버로드, String 복사 없이 일부 구간만 파싱하려고 만든 기능

     

    이전 코드

    Integer.parseInt(s.substring(1,4));

     

    해당 메서드 사용

    Integer.parseInt(s, 1, 4, 10);

    '공부' 카테고리의 다른 글

    I/O Bound와 Context Switching  (0) 2025.07.18
    정수론 공부  (0) 2025.06.23
    DB 고민: PK, 정규화와 역정규화  (1) 2024.07.01
    [JAVA] final  (0) 2024.06.22
    [JAVA] Thread Quiz  (0) 2024.06.20
Designed by Tistory.