JAVA

day03) 문자열 내장 메소드

code_learner 2021. 12. 23. 23:57

다른 자료형과는 다르게 String은 객체를 생성할 수 있다.

따라서 String에서만 사용 할 수 있는 메서드가 여럿 있다.

	String str = "apple";
	System.out.println(str.charAt(1));
	//★★index는 [0]부터 시작!
        //2번째에 있는 글자를 출력
        //p
		
        System.out.println(str.length());
        //str의 길이를 알려주는 메서드 
        //5
		
        System.out.println(str.substring(1,3));
        //1이상 3미만의 글자를 출력 
        //pp
        
	System.out.println(str.toUpperCase());
        System.out.println(str);
        //소문자를 대문자로 변경
        //str자체에 변화를 주지 않는다!
        //APPLE
        //apple