1.==是进行对象的地址值比较,如果确实需要字符串的内容比较;
//public boolean equals(Object obj)参数可以是任何对象;
//推荐,写法
“abc”.equals(str);
A.equalsIgnoreCase(B);//忽略大小写
2.字符串的获取相关方法
public int length();
public String concat(String str);
public char charAt(int index);
public int indexOf(String str);
//查找参数字符串在本字符串当中首次出现的索引位置,如果没有返回-1值。
3.字符串的截取方法
public String substring(int index);
public String substring(int begin ,int end)
//[begin,end),包含左边,不包含右边
4.字符串的转换方法
public char[] toCharArray();将当前字符串拆分为字符数组作为返回值
public byte[] getBytes();获得当前字符串底层的字节数组
public String replace();所有的老字符串替换为新的字符串
char [] chars = "Hello".toCharArray();//转化为字符数组
byte []bytes = "abc".getBytes();//转化为字节数组
String str2 = str1.replace(target:"0",repalcement:"*");
5.字符串的分割方法
public String[] split(String regex)
split方法的参数其实是一个“正则表达式”;
“.”split的时候应该写“//.”
String [] array = str1.split(regex:",");