首页 > 其他分享 >String类中的判断方法 day11

String类中的判断方法 day11

时间:2024-08-08 20:42:11浏览次数:6  
标签:String s3 System boolean day11 字符串 类中 out

package com.shujia.day11;


/*
    String类中的判断功能:
        boolean equals(Object obj)     String类中的equals是重写父类Object中的equals方法,比较的是内容
        boolean equalsIgnoreCase(String str)    忽略大小写比较字符串内容
        boolean contains(String str)    判断大字符串中是否有小字符串
        boolean startsWith(String str)  判断字符串是否以指定字符串开头
        boolean endsWith(String str)    判断字符串是否以指定字符串结尾
        boolean isEmpty()               判断字符串是否为空字符串

 */
public class StringDemo4 {
    public static void main(String[] args) {
        String s1 = "hello";
        String s2 = "HelLO";

        //boolean equals(Object obj)
        boolean b1 = s1.equals(s2); // String类中的equals是重写父类Object中的equals方法,比较的是内容
        System.out.println(b1);


        //boolean equalsIgnoreCase(String str)
        boolean b2 = s1.equalsIgnoreCase(s2); // 忽略大小写比较字符串内容
        System.out.println(b2);

        //boolean contains(String str) // 判断大字符串中是否有小字符串
        String s3 = "魏一民真shujia帅";
        String s4 = "shujia666";
        boolean b3 = s3.contains(s4);
        System.out.println(b3);

        //boolean startsWith(String str) // 判断字符串是否以指定字符串开头
        boolean b4 = s3.startsWith("魏一");
        System.out.println(b4);

        //boolean endsWith(String str) // 判断字符串是否以指定字符串结尾
        boolean b5 = s3.endsWith("帅");
        System.out.println(b5);

        // boolean isEmpty() 判断字符串是否为空字符串
        boolean b6 = s3.isEmpty();
        System.out.println(b6);
        s3 = "";
        System.out.println(s3.isEmpty());
//        s3 = null;
//        System.out.println(s3.isEmpty()); // NullPointerException


    }
}

标签:String,s3,System,boolean,day11,字符串,类中,out
From: https://www.cnblogs.com/qiwei-bigdata/p/18349681

相关文章

  • String类,及构造方法day11
    packagecom.shujia.day11;/*String:字符串解释:白话文描述:使用一个串将一个一个字符串起来的串儿叫字符串。专业术语:使用双引号将若干个字符括起来的字符序列官网概述:String类代表字符串。Java程序中的所有字符串文字(例如"......
  • String和StringBuffer作为参数传递的区别
    String和StringBuffer作为参数传递,相同的是都重写了父类Object的toString方法,所以展示出来的不是地址值,而是对象内容以下是两者的不同:一、String作为参数传递:因为没有new,所以内容只在方法区,有相同的字符就会指向常量池中同一个地址值,没有就会创建一个新的,但是方法调用的时候,只......
  • from type [java.lang.String] to type [org. apache.kafka.clients.consumer.Consume
    kafka消费消息的时候,报错Noconverterfoundcapableofconvertingfromtype[java.lang.String]totype[org.apache.kafka.clients.consumer.ConsumerRecord<??>,没有消费到数据,这种情况可能是发送方发送的数据是封装了多个ConsumerRecord<??>对象发送过来的,需要用Consume......
  • 如何在通用 Python 类中输入 __eq__ ?
    当我定义带有泛型类型参数的类型时(例如K/V映射的键和值),我似乎无法编写合适的isinstance检查来实现__eq__:fromcollectionsimportOrderedDictfromcollections.abcimportMutableMappingfromtypingimportTypeVarK=TypeVar("K")......
  • toString()方法 day10
    /*Object类学习:是java中所有的共同的父类,包括数组1、Object类是属于java.lang包下的,将来使用的时候不需要导包2、构造方法只有一个无参的构造方法3、方法都不是静态的,以为着要有对象才可以调用成员方法:publicinthashCode()......
  • 面向对象程序设计(C++)之 String 类
    1.String构造函数String可以理解为一个字符数组,在创建String类型变量的时候可以使用很多形式,因为String有很多实用的构造函数首先使用String类要包含头文件#include<string>接下来使用代码依次演示上述构造函数的用法: #include<iostream>#include<string>......
  • C++ STL与string类
    一什么是STL?STL,全称是标准模板库(StandardTemplateLibrary),是C++标准库的一部分。STL提供了一些常用的数据结构和算法,帮助开发者更方便、高效地编写代码。通过使用STL,开发者不需要重复造轮子,可以直接使用已经优化好的组件,提高了代码的可读性和可维护性。二STL的六大组件1.......
  • CF305E Playing with String
    难点在于读题发现\(l\)总取\(1\)即可,然后稍加转换就变成个傻逼题了有个显而易见的\(O(n^3)\)的区间DP做法,即考虑记录每个区间的SG函数值,然后枚举分界点转移但仔细思考我们会发现能进行操作的只有初始时\(s_{i-1}=s_{i+1}\)的位置,并不会经过某些操作后使得一个本来不......
  • 【C++】string类
    ......
  • es6-string-html vscode插件 js里面template的高亮插件 无构建vue使用
    es6-string-htmlvscode插件js里面template的高亮插件无构建vue使用这个插件可以让js里面的template的字符串高亮,前面加/*html*/Refference:无构建和打包,浏览器直接吃上Vue全家桶?https://juejin.cn/post/7399094428343959552......