当前位置: 首页 > news >正文

Java-字符串-String类

1 需求

1.1 Field Summary


1.2 Constructor Summary

  • public String() : 空构造
  • public String(byte[] bytes) : 把字节数组转成字符串
  • public String(byte[] bytes,int index, int length) : 把字节数组的一部分转成字符串
  • public String(char[] value) : 把字符数组转成字符串
  • public String(char[] value,int index, int count) : 把字符数组的一部分转成字符串

1.3 Method Summary

  • 判断字符串是否为空
    • public boolean isEmpty()
  • 获取字符串的长度
    • public int length()
  • 判断字符串是否相等
    • public boolean equals(Object anObject)
    • public boolean contentEquals(StringBuffer sb)
    • public boolean contentEquals(CharSequence cs)
    • public boolean equalsIgnoreCase(String anotherString)
  • 判断是否包含子字符串
    • public boolean contains(CharSequence s)
    • public boolean matches(String regex)
  • ……
    • public boolean startsWith(String prefix, int toffset)
    • public boolean startsWith(String prefix)
  • ……
    • public boolean endsWith(String suffix)
       
  • 分割字符串
    • public String[] split(String regex)
    • public String[] split(String regex, int limit)
  • ……
    • public int indexOf(int ch)
    • public int indexOf(int ch, int fromIndex)
    • public int indexOf(String str)
    • public int indexOf(String str, int fromIndex)
  • 判断某个字符最后出现的位置
    • public int lastIndexOf(int ch)
    • public int lastIndexOf(int ch, int fromIndex)
    • public int lastIndexOf(String str)
    • public int lastIndexOf(String str, int fromIndex)
  • 字符串替换
    • public String replace(char oldChar, char newChar)
    • public String replace(CharSequence target, CharSequence replacement)
    • public String replaceFirst(String regex, String replacement)
    • public String replaceAll(String regex, String replacement)
  • 字符串查找
    • public String substring(int beginIndex)
    • public String substring(int beginIndex, int endIndex)
    • public CharSequence subSequence(int beginIndex, int endIndex)

2 接口


3.X 示例:字符串定义(两种方式)

public class Test {public static void main(String[] args) {String s1 = "hello";String s2 = new String("hello");System.out.println(s1 == s2);}
}

参考资料

JAVA字符串的两种定义方式的区别_java中字符串的定义方式及区别-CSDN博客


3.X 示例:未初始化报错

public class Test {public static void main(String[] args) {String s1;System.out.println(s1);}
}


3.X 示例:空字符串

public class Test {public static void main(String[] args) {String s1 = "";System.out.println(s1.isEmpty());System.out.println(s1.length());}
}


3.X 示例:null字符串

public class Test {public static void main(String[] args) {String s1 = null;System.out.println(s1.isEmpty());}
}

public class Test {public static void main(String[] args) {String s1 = null;System.out.println(s1.length());}
}


4 参考资料

java基础-String_public string{byte[] bytes,-CSDN博客

http://www.lryc.cn/news/275794.html

相关文章:

  • ubuntu安装docker指定版本
  • 说一下 jsp 的 4 种作用域?
  • 性能分析与调优: Linux 使用ELRepo升级CentOS内核
  • 【【RTC实时时钟实验 -- 在HDMI上显示-FPGA 小实验】】
  • Flutter 图片和资源的高效使用指南
  • RedisTemplate 怎么获取到链接信息?怎么获取到所有key?怎么获取指定key?
  • 【Unity】动态申请权限
  • tp8/6 插件PhpOffice\PhpSpreadsheet导入表格
  • Android studio VideoView 应用设计
  • Python基础(十八、文件操作读取)
  • Mac 16g约等于Windows多少g?
  • 快麦ERP退货借助APPlink快速同步CRM
  • springMVC获取请求参数的方式
  • android常用方法
  • Linux内核--网络协议栈(一)Socket通信原理和实例讲解
  • Spring事务(2):声明式事务管理案例-转账(xml、注解)
  • NACHI机器人模拟示教器如何切换中文
  • 用通俗易懂的方式讲解:使用 Mistral-7B 和 Langchain 搭建基于PDF文件的聊天机器人
  • 综合智慧能源监测管理平台,实现能源管理“透明”化
  • 【大数据进阶第三阶段之Datax学习笔记】使用阿里云开源离线同步工具DataX 实现数据同步
  • kotlin chunked 和 windowed
  • C语言光速入门笔记
  • Flutter+Go_Router+Fluent_Ui仿阿里网盘桌面软件开发跨平台实战-买就送仿小米app开发
  • 内联函数的作用
  • Simpy简介:python仿真模拟库-02/5
  • Kafka高级应用:如何配置处理MQ百万级消息队列?
  • LIN总线学习笔记(1)-总线传输规范
  • Qt界面篇:Qt停靠控件QDockWidget、树控件QTreeWidget及属性控件QtTreePropertyBrowser的使用
  • H266/VVC网络适配层概述
  • new FormData 同时发送表单 json 以及文件二进制流