zoukankan      html  css  js  c++  java
  • contains方法

    Java String.contains()方法,当且仅当此字符串包含指定的char值序列时,返回true

    public static void main(String[] args) {
    String str1 = "abcdefg", str2 = "hijklmn";
    CharSequence a = "abc";
    boolean b = str1.contains(a);
    System.out.println("第一条返回结果是 : " + b);
    b= str2.contains("!");
    System.out.println("第二条返回结果是: " + b);
    }

    编译之后的输出:

      第一条返回结果是:true

      第二条返回结果是:false

    例如:从前端传过来name,如果name这个字符串中含有"j"就set到realName中,否则就set到Name中
    if(user.getName().toLowerCase().contains("j")){
    user.setRealName(user.getName());
    }else{
    user.setName(user.getName());
    }
    toLowerCase():不在区分大小写
    contains():如果字符串中包含指定的char值序列时,返回true,否则就返回false;


     

     

  • 相关阅读:
    Spring MVC(一)
    Spring-IOC总结
    IT
    Spring基础
    Maven
    Ajax笔记
    数据库和SQL语言
    JDBC
    拦截器
    文件上传
  • 原文地址:https://www.cnblogs.com/thcy1314/p/10687667.html
Copyright © 2011-2022 走看看