• "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
  • 相关阅读:
    Tomcat 三种运行方式
    MariaDB介绍
    Nginx 平滑升级
    代理命令 proxy_pass 详解
    Nginx 和 Tomcat 负载均衡
    基于Apache和tomcat实现负载均衡
    centos7 通过源码编译的方式安装和配置Apache
    基于nginx结合openssl实现https
    HTTP 和 HTTPS 区别
    linux系统中修改别名配置文件,构建命令别名
  • 原文地址:https://www.cnblogs.com/zghull/p/2892302.html
Copyright © 2020-2023  润新知