1. 字符串常见方法1:
length(): 返回字符串的长度
isEmpty(): 判断字符串是否是空,如果是空字符串,返回true
charAt(int index): 找到指定下标的字符
codePointAt(int index): 找到指定下标字符的编码
getBytes() / getBytes(String charset) / getBytes(Charset charset): 将字符串按照指定的编码方式转换成为字节数组
equals(): 用来比较两个字符串的内容是否相等
compareTo(): 比较两个字符串,得到的结果是一个int类型的值
hashCode(): 用来计算字符串的哈希值
startsWith(): 判断字符串是否以指定的内容开始
endsWith(): 判断字符串是否以指定的内容结束
indexOf(int codePoint[,int index]) / indexOf(char c[,int index]): 查找字符在字符串里的下标
indexOf(String str[,int index]): 查找字符串在指定字符串里的下标
lastIndexOf():查找指定字符(串)最后一次出现的下标
subString(int beginIndex[,int endIndex]): 从指定的位置开始(包含)截取字符串,到指定的位置结束(不包含)
toLowerCase() / toUpperCase(): 变小写和变大写
public class StringMethod1 {
public static void main(String[] args) {
String s = "helloword";
System.out.println(s.length()); // 返回字符串的长度
System.out.println(s.isEmpty()); // false
System.out.println("".isEmpty()); // true
System.out.println(" ".isEmpty()); // false
System.out.println(s.charAt(3));
System.out.println(s.codePointAt(0));
System.out.println(s.codePointBefore(1));
System.out.println(s.codePointCount(3, 7)); // 不包含结尾
System.out.println(Arrays.toString(s.getBytes())); // [97, 116, 103, 117, 105, 103, 117]
System.out.println(Arrays.toString("你好".getBytes())); // [-28, -67, -96, -27, -91, -67]
System.out.println("abc".compareTo("Abc"));
System.out.println("good".startsWith("g"));
System.out.println("good".endsWith(&