☕JAVA/🔎 공부 [JAVA]
[JAVA] charAt()
디카페인라떼
2022. 8. 6. 23:02
- 정의
String으로 저장된 문자열 중에서 한 글자만 선택해서 char 타입으로 변환해줌
- 형태
public class Main {
public static void main(String[] args) {
String str = new String();
char c = ' ';
str = "Nice to meet you";
c = str.charAt(0);
System.out.println(c);//N
}
str이 가리키고 있는 문자열에서 인덱스번호에 있는 문자를 char 타입으로 변환!
참조변수.charAt(문자번호);