setXxx_getXxx 2016-12-31 12:00 采纳率: 57.1%
浏览 3759
已采纳

String类下的contains()方法报错

package cn.itcast_03;

/*

  • 判断功能:
  • boolean equals(Object obj):比较字符串的内容是否相同,区分大小写
  • boolean equalsIgnoreCase(String str):比较字符串的内容是否相同,忽略大小写
  • boolean contains(String str):判断大字符串中是否包含小字符串
  • boolean startsWith(String str):判断字符串是否是否以某个指定的字符串开头
  • boolean endsWith(String str):判断字符串是否以某个指定的字符串结尾
  • boolean isEmpty():判断字符串是否为空。
  • 注意:
  • 字符串内容为空和字符串对象为空。
  • String s = "";
  •  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)
  • 写回答

2条回答 默认 最新

  • 全栈极简 博客专家认证 2016-12-31 13:09
    关注

    我试了下你的代码没有问题,可以运行并得到正确结果。

    修改看下是否是jdk的问题,http://blog.csdn.net/xl553488213/article/details/40512633

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容