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
你可以关注下 ITIL先锋这个微信公众号 上面每天会更新IT行业最前沿资讯和各种类别的IT资料,感觉工作学习都比较有用