string - 常用方法

版权声明:[ws - 兮的博客] - 空间专属,未经声明不得私自转载 https://blog.csdn.net/qq_41463655/article/details/82911964
String x = new String();
             a  b  c  d   e   f   g
byte [] j ={97,98,99,100,101,102,103,};    ascii 输出
char[] jj = {'a', 'b', 'g', 't','o'};      字符 输出
String x1 = new String(j);                 字节字符串
String x2 = new String(j,2,5);             截取数组字符串   2索引   3长度 
String x3 = new String("qwe");             new 值(地址不同)
String x4 = j.trim();                      去掉两边空格
int  x5 = i.indexOf("s");                  第一次 出现    索引
int  x5 = i.indexOf("s",3);                第一次 出现    索引(指定位置开始)
int  x6 = j.lastIndexOf("s");              后往前 第一次 索引
int  x7 = j.lastIndexOf("s",3);            后往前 第一次 索引(指定位置开始)
char x8 = j.charAt(5);                     指定 索引 字符 
char x9 = 输入字符.charAt(j);               获得所有输入字符(遍历j)

j.charAt(0)                                检索字符串中的第一个字符,               
j.charAt(str.length()-1)                   检索最后一个字符
 String x10 = j.substring(5);              包括开始索引   后面的所有字符
 String x11 = j.substring(4, 5);          (截取字符串)包括开始索引,不包括结束索引
 byte[] x12 = j.getBytes();                获得字符串   对应的字节数组(请遍历)
 String x13 = String.valueOf(true);(j)  

 j.toUpperCase()              把字符串 转换成 大写
 j.toLowerCase()              把字符串 转换成 小写
 j.concat(jj);                拼接
 String.valueOf(x1);          把布尔类型  转换成字符串

 j.endsWith("ld")             判断字符串结尾
 j.equals("helloworld")       判断两个字符串是否相等,equals比较的是值
 "helloworld".equals(j)       判断两个字符串是否相等   建议使用    
 x.contains  ("ello")         连续的字符串
 x.startsWith("hel")          字符串开头
 x .isEmpty()                 是否是空串
 "".isEmpty()                 空串 
         
 String i = "3000-3999-uuu-999-kkk-2323";
 String[] ii = i.split(" - ");               字符串分割
 String i1 = i.replace('-','#');             替换   1  原有  2 换    单引号
 
 String i = "3000*3999*uuu*999*kkk*2323";--------------------------------- 
 String[] ii = i.split(" * ");     分割
 String i2 = i.replace("3999","8888");       替换    1 -原有  2 -换    双引号

猜你喜欢

转载自blog.csdn.net/qq_41463655/article/details/82911964