zoukankan      html  css  js  c++  java
  • "bs".endsWith()的使用注意,别用错了

    "bs"

    bs.endsWith(s1)和s1.endsWith("bs"),差别很大

    描述

    java.lang.String.endsWith() 方法返回的测试该字符串是否以指定后缀sffix结束

    声明

    以下是声明java.lang.String.endsWith()方法

    public boolean endsWith(String suffix)
    

    参数

    • suffix -- This is the suffix.

    返回值

    该方法返回一个true,如果参数表示的字符序列是由该对象表示的字符序列的后缀,否则返回false.

    异常

    • NA

    实例

    下面的示例演示使用的java.lang.String.endsWith()方法.

    package com.yiibai;
    
    import java.lang.*;
    
    public class StringDemo {
    
      public static void main(String[] args) {
      
        String str = "www.yiibai.com";
        System.out.println(str);
    
        // the end string to be checked
        String endstr1 = ".com";
        String endstr2 = ".org";
    
        // checks that string str ends with given substring
        boolean retval1 = str.endsWith(endstr1);
        boolean retval2 = str.endsWith(endstr2);
    
        // prints true if the string ends with given substring
        System.out.println("ends with " + endstr1 + " ? " + retval1);
        System.out.println("ends with " + endstr2 + " ? " + retval2);
      }
    }
    

    让我们来编译和运行上面的程序,这将产生以下结果:

    www.yiibai.com
    ends with .com ? true
    ends with .org ? false
  • 相关阅读:
    线程数与多核CPU的关系,VMware中核数的设置
    shell基础编程
    MySql中join基础
    OneNote发布至博客园
    java获取系统换行符,路径分割符
    使用shell实现简单的词频统计
    Kylin系列之二:原理介绍
    MySQL 配置文件my.cnf
    SQLServer LinkServer 链接服务器
    sp_tableoption
  • 原文地址:https://www.cnblogs.com/zghull/p/2892302.html
Copyright © 2011-2022 走看看