다른 자료형과는 다르게 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
'JAVA' 카테고리의 다른 글
day04-과제)삽입정렬 (0) | 2021.12.26 |
---|---|
day03)배열 (0) | 2021.12.24 |
day03) Random, 형변환, Final (0) | 2021.12.23 |
day02)제어문 관련 알고리즘 (0) | 2021.12.23 |
day02) 제어문(반복문) (0) | 2021.12.22 |
댓글