728x90
API String 클래스 중 startWith , endsWith 을 공부하였다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
package StringTest;
public class Test2_2 {
public static void main(String[] args) {
/* 기존 문자열이 지정한 문자열로 시작되는지를 판단? startsWith() */
String str1 = "apple";
String str2 = "app";
if(str1.startsWith(str2))
System.out.println("st1변수는 app로 시작합니다.");
else
System.out.println("st1변수는 app로 시작하지 않습니다.");
/* 기존 문자열이 지정한 문자열로 끝나는지를 판단? endsWith() */
str1 = "apple";
str2 = "le";
if(str1.endsWith(str2))
System.out.println("st1변수는 le로 끝납니다.");
else
System.out.println("st1변수는le로 끝나지 않습니다.");
}
}
|
str1.startsWith(str2)
str1변수를 str2변수의 시작부분과 일치하는지 확인
str1.startWith(str2) -> str1이 str2로 시작하면 true 아니면 false
str1.endsWith(str2)
str1변수를 str2변수의 끝 부분과 일치하는지 확인
str1.endWith(str2) -> 끝부분이 일치하면 true 아니면 false
728x90
'Web > Spring , Springboot , JPA' 카테고리의 다른 글
AWT 연습 (0) | 2020.04.02 |
---|---|
windowbuilder 사용 (0) | 2020.04.02 |
[JAVA] 순서도 (0) | 2020.03.14 |
[JAVA] 타입변환 (0) | 2020.03.14 |
[Java ] 자바 언어의 특징 (0) | 2020.03.14 |