快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

java中判断字符串是否包含指定字符的方法-创新互联

java怎么判断字符串是否包含指定字符?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

目前成都创新互联公司已为近1000家的企业提供了网站建设、域名、虚拟主机网站托管、企业网站设计、民勤网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

1、startsWith()

public boolean startsWith(String prefix, int toffset)
or
public boolean startsWith(String prefix)

import java.io.*;
 
public class Test{
   public static void main(String args[]){
      String Str = new String("Welcome to Yiibai.com");
 
      System.out.print("Return Value :" );
      System.out.println(Str.startsWith("Welcome") );
 
      System.out.print("Return Value :" );
      System.out.println(Str.startsWith("Tutorials") );
 
      System.out.print("Return Value :" );
      System.out.println(Str.startsWith("Yiibai", 11) );
   }
}

public static void main(String[] args) {
 
        String str = "abc";
 
        boolean status = str.contains("a");
 
        if(status){
            System.out.println("包含");
 
        }else{
            System.out.println("不包含");
        }
 
    }

public static void main(String[] args) {
    String str1 = "abcdefg";
    int result1 = str1.indexOf("ab");
    if(result1 != -1){
        System.out.println("字符串str中包含子串“ab”"+result1);
    }else{
        System.out.println("字符串str中不包含子串“ab”"+result1);
    }
}

关于java怎么判断字符串是否包含指定字符问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。


文章标题:java中判断字符串是否包含指定字符的方法-创新互联
本文地址:http://6mz.cn/article/ddopdc.html

其他资讯