package cn.itcast_03;
/*
String s = null;
*/
public class StringDemo {
public static void main(String[] args) {
// 創建字符串對象
String s1 = "helloworld";
String s2 = "helloworld";
String s3 = "Helloworld";
// boolean equals(Object obj):比較字符串的內容是否相同,區分大小寫
System.out.println("equals:" + s1.equals(s2));
System.out.println("equals:" + s1.equals(s3));
System.out.println("--------------------");
// boolean equalsIgnoreCase(String str):比較字符串的內容是否相同,忽略大小寫
System.out.println("equals:" + s1.equalsIgnoreCase(s2));
System.out.println("equals:" + s1.equalsIgnoreCase(s3));
System.out.println("--------------------");
// boolean contains(String str):判斷大字符串中是否包含小字符串
System.out.println(s1.contains("hello"));//這行報錯
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files
The method contains(CharSequence) from the type String refers to the missing type CharSequence
at cn.itcast_03.StringDemo.main(StringDemo.java:35)
我試了下你的代碼沒有問題,可以運行並得到正確結果。
修改看下是否是jdk的問題,http://blog.csdn.net/xl553488213/article/details/40512633