小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

String類的判斷功能

 櫻花夢_張藝馨 2016-10-28
package ss1;
/**
 *String類的判斷功能:
 *public boolean equals(Object anObject) 將此字符串與指定的對象比較,內(nèi)容是否相同,區(qū)分大小寫
 *public boolean equalsIgnoreCase(String anotherString) 將此字符串與指定的對象比較,內(nèi)容是否相同,不區(qū)分大小寫
 *public boolean contains(CharSequence s) 判斷大字符串中是否包含小字符串
 *public boolean startsWith(String prefix) 測試此字符串是否以指定的前綴開始。
 *public boolean endsWith(String suffix) 測試此字符串是否以指定的后綴結(jié)束。
 *public boolean isEmpty()  判斷字符串是否為空,當(dāng)且僅當(dāng) length() 為 0 時返回 true。
 *注意:
 *    字符串內(nèi)容為空和字符串對象為空.
 *    String s ="";
 *    String s1 = null;
 */
public class Menu {
 public static void main(String[] args) {
  
  String s1 = "helloworld";
  String s2 = "helloworld" ;
  String s3 = "Helloworld";
  System.out.println(s1.equals(s2)); //true
  System.out.println(s1.equals(s3)); //false
  System.out.println(s1.equalsIgnoreCase(s3)); //true
  System.out.println(s1.contains("hell")); //true
  System.out.println(s1.contains("hw")); //false
  System.out.println(s1.startsWith("hello")); //true
  System.out.println(s1.startsWith("h")); //true
  System.out.println(s1.endsWith("ld")); //true
  String s ="";
  String ss = null;
  System.out.println(s1.isEmpty()); //false
  System.out.println(s.isEmpty()); //true
  System.out.println(ss.isEmpty()); //NullPointerException 原因是ss未創(chuàng)建對象,無法調(diào)方法。
 }
}
結(jié)果:
true
false
true
true
false
true
true
true
false
true
Exception in thread "main" java.lang.NullPointerException
 at ss1.Menu.main(Menu.java:35)

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多