String03- 공통 대상 부재 방법 (함수 결정) 03
String 클래스 기능을 결정 :
부울에게 등호 (객체 obj) 등 : 비교 문자열은 같은 내용, 대소 문자 구분이
비교 문자열이 같은 내용을 가지고, 사례 무시 : 부울 equalsIgnoreCase (문자열 STR)
(문자열 STR)를 포함 부울 : 분석을 큰 문자열은 작은 캐릭터가 포함
startsWith (문자열 STR) 부울 : 지정된 문자열을 문자열 개시 여부를 결정
지정된 문자열 여부 문자열 단부 결정 : endsWith (문자열 STR) 부울
(IsEmpty 함수 부울 ) : 문자열이 비어 있는지의 여부를 판단한다.
注意:
字符串内容为空和字符串对象为空。
String s = "";
String s = null;
메소드의 개요 boolean equals (Object obj) : 비교 문자열은 민감한 경우 같은 내용을 가지고
public class StringDemo {
public static void main(String[] args) {
String s1 = "helloworld";
String s2 = "helloworld";
String s3 = "helloworld";
System.out.println("equals()--"+s1.equals(s2));
System.out.println("equals()--"+s1.equals(s3));
}
}
결과 :
equals()--true
equals()--true
부울 equalsIgnoreCase (문자열 STR) : 문자열 비교 내용이 동일 무시하는 경우입니다
public class StringDemo {
public static void main(String[] args) {
String s1 = "helloworld";
String s2 = "helloworld";
String s3 = "HELLOWORLD";
System.out.println("equalsIgnoreCase()--"+s1.equalsIgnoreCase(s2));
System.out.println("equalsIgnoreCase()--"+s1.equalsIgnoreCase(s3));
}
}
결과 :
equalsIgnoreCase()--true
equalsIgnoreCase()--true
부울 (문자열 str을) 포함 : 작은 대형 문자열을 분석하는 문자열을 포함
public class StringDemo {
public static void main(String[] args) {
String s1 = "helloworld";
String s2 = "helloworld";
System.out.println("contains()--"+s1.contains("llow"));
System.out.println("contains()--"+s1.contains("hd"));
}
}
결과 :
contains()--true
contains()--false
부울 startsWith (String str) 캐릭터 라인을, : 결정 여부를 지정된 문자열에 문자열의 시작
public class StringDemo {
public static void main(String[] args) {
String s1 = "helloworld";
String s2 = "helloworld";
System.out.println("startsWith()--"+s1.startsWith("h"));
System.out.println("startsWith()--"+s1.startsWith("H"));
}
}
결과 :
startsWith()--true
startsWith()--false
부울 endsWith (String str) 캐릭터 라인을, : 결정 여부를 지정된 문자열로 문자열의 끝
public class StringDemo {
public static void main(String[] args) {
String s1 = "helloworld";
String s2 = "helloworld";
System.out.println("endsWith()--"+s1.endsWith("d"));
System.out.println("endsWith()--"+s1.endsWith("D"));
}
}
결과 :
endsWith()--true
endsWith()--false
부울 IsEmpty 함수는 () : 문자열이 비어 있는지 여부를 결정합니다
public class StringDemo {
public static void main(String[] args) {
String s1 = "helloworld";
String s2 = "";
String s3 = null;
System.out.println(s1.isEmpty());
System.out.println(s2.isEmpty());
System.out.println(s3.isEmpty());//空指针异常
}
}
결과
false
true
Exception in thread "main" java.lang.NullPointerException
at com.ginger.demo01.StringDemo.main(StringDemo.java:12)