startsWith()와 endWith()는 함수명으로 유추해볼 수 있듯이, 문자열에 대해 특정 문자로 시작하는지/끝나는지를 확인할 수 있는 함수 입니다.
아래는 간단한 예시 입니다.
String str = "@@myId";
System.out.println(str.startsWith("@")); // true
System.out.println(str.endWith("@")); // false
이런 식으로 특정 문자열에 대한 확인을 할 수 있습니다.
회원가입 하려는 사용자가 유효하지 않은 문자열을 사용하지는 않는지, 시작/끝 문자열에 있으면 안되는 문자열이 있는지 등등 확인할 때 활용될 수 있겠네욤
startsWith()
Syntax
public boolean startsWith(String chars)
Return
boolean
- true: 확인하려는 문자열에 특정 문자열로 시작한다.
- false: 확인하려는 문자열이 특정 문자열로 시작하지 않는다.
endWith()
Syntax
public boolean endWith(String chars)
Return
boolean
- true: 확인하려는 문자열에 특정 문자열로 끝난다.
- false: 확인하려는 문자열이 특정 문자열로 끝나지 않는다.
'BackEnd > Java&Spring' 카테고리의 다른 글
Intellij) JUnit5 설정할 사람 괌 (0) | 2023.07.27 |
---|---|
Error) java: class, interface, or enum expected 해결 (0) | 2023.06.26 |
@JsonProperty와 @JsonNaming (0) | 2023.03.17 |
Java의 Hash 알고리즘 MessageDigest (0) | 2023.03.16 |
HTTP Query Parameter에서 Arrary List 사용 (0) | 2023.02.01 |