String类

1、String类的构造方法

2、String类中的常用方法演示

  • 求字符串长度方法,字符串.length()
  • String substring(int beginIndex):返回从指定索引开始到字符串结束的子字符串
  • String substring(int beginIndex, int endIndex):返回从指定索引开始到指定索引结束的子字符串(含头不含尾)

  • boolean startWith(String prefix)方法:判断字符串是否以指定的前缀开始
  • boolean endWith(String suffix)方法:判断字符串是否以指定的后缀结束
  • boolean contains(CharSequence s):判断字符串是否包含指定的char字符序列
  • int indexOf(String str):返回子字符串在此字符串中第一次出现的索引
  • byte getBytes():将字符串编码为byte序列,返回一个byte数组
  • char[] toCharArray():将字符串转换为一个char数组
  • boolean equals(String str):判断字符串是否与指定的字符串相等
  • boolean equalsIgnoreCase(String str):比较两个字符串,不考虑大小写

3、String类练习

  1. 分别统计一个字符串中大写字母,小写字母和数字出现的次数
  2. 大小写字母的转换
  3. 字符串查找

原文地址:https://www.cnblogs.com/alphajuns/p/9864492.html