본문 바로가기

Java/문법

[Java/문법] String 클래스의 주요 메서드

✏️ 주요 메서드

메서드 문법 설명
substring() String substring(int beginIndex)
String substring(int beginIndex, int endIndex)
문자열의 일부를 추출합니다
equals() boolean equals(Object obj) 두 문자열의 내용이 동일한지 비교합니다
 

startsWith() boolean startsWith(String prefix)
boolean startsWith(String prefix, int toffset)
문자열이 지정된 접두사로 시작하는지 확인합니다
toCharArray() char[] toCharArray() 문자열을 문자 배열로 변환합니다
 

length() int length() 문자열의 길이를 반환합니다
charAt() char charAt(int index) 지정된 인덱스의 문자를 반환합니다
indexOf() int indexOf(int ch)
int indexOf(String str)
지정된 문자나 문자열의 첫 번째 출현 위치를 반환합니다
 

replace() String replace(char oldChar, char newChar)
String replace(CharSequence target, CharSequence replacement)
문자열 내의 특정 문자나 문자열을 다른 문자나 문자열로 치환합니다
toLowerCase() String toLowerCase() 문자열을 모두 소문자로 변환합니다
toUpperCase() String toUpperCase() 문자열을 모두 대문자로 변환합니다
trim() String trim() 문자열의 앞뒤 공백을 제거합니다
 

split() String[] split(String regex)
String[] split(String regex, int limit)
문자열을 지정된 구분자를 기준으로 분리하여 배열로 반환합니다
 

반응형