[Java] startsWith/endsWith

이지현·2023년 4월 11일
0
post-thumbnail

✔️ startsWith

  • 대상 문자열이 특정 문자 또는 문자열로 시작하는지 체크
public class etcPractice {
    public static void main(String[] args) {
        String str = "자바";
        System.out.println(str.startsWith("자")); // true
    }
}

✔️ endsWith

  • 대상 문자열이 특정 문자 또는 문자열로 끝나는지 체크
public class etcPractice {
    public static void main(String[] args) {
        String str = "자바";
        System.out.println(str.endsWith("바")); // true
    }
}
profile
2023.09 ~ 티스토리 이전 / 2024.04 ~ 깃허브 블로그 이전

0개의 댓글