Java substring()방법

2100 단어 Java
자바 String 클래스 substring()방법 은 문자열 의 하위 문자열 을 되 돌려 줍 니 다.
문법
public String substring(int beginIndex)

 

public String substring(int beginIndex, int endIndex)

매개 변수
  • beginIndex–시작 색인(포함),색인 은 0 부터 시작 합 니 다
  • endIndex–끝 색인(포함 되 지 않 음)..

  • 반환 값
    하위 문자열.
    public class Test {
         
        public static void main(String args[]) {
         
            String Str = new String("www.runoob.com");
     
            System.out.print("    :" );
            System.out.println(Str.substring(4) );
     
            System.out.print("    :" );
            System.out.println(Str.substring(4, 10) );
        }
    }
    

    위의 프로그램 실행 결 과 는 다음 과 같 습 니 다.
        :runoob.com
        :runoob
    

    좋은 웹페이지 즐겨찾기