(1)boolean isEmpty(): 判断字符串是不是空串,如果是空的就返回true
(2)char charAt(int index): 返回索引上的字符
(3)String toLowerCase(): 字符串转成小写
(4)String toUpperCase(): 字符串转成大写
(5)String repalce(char oldChar, char newChar): 将字符串中的老字符,替换为新字符
(6)String repalce(String old, String newstr): 将字符串中的老字符串,替换为新字符串
(7)String trim(): 去掉字符串两端空格
代码示例:
package cn.zxj.comn; /* (1)boolean isEmpty(): 判断字符串是不是空串,如果是空的就返回true (2)char charAt(int index): 返回索引上的字符 (3)String toLowerCase(): 字符串转成小写 (4)String toUpperCase(): 字符串转成大写 (5)String repalce(char oldChar, char newChar): 将字符串中的老字符,替换为新字符 (6)String repalce(String old, String newstr): 将字符串中的老字符串,替换为新字符串 (7)String trim(): 去掉字符串两端空格 */ class Test { public static void main(String[] args){ String s= ""; //判断字符串是不是空串 if(s.isEmpty()){ System.out.println("s是空字符串!"); } String s1= "123"; //返回索引上的字符 System.out.println(s1.charAt(0)); String s2= "abC"; //字符串转成小写 System.out.println(s2.toLowerCase()); String s3= "abC"; //字符串转成大写 System.out.println(s2.toUpperCase()); String s4= "abC"; //字符串中的老字符,替换为新字符 System.out.println(s4.replace('a','d')); String s5= "abC"; //将字符串中的老字符串,替换为新字符串 System.out.println(s5.replace("ab","de")); String s6= " abc "; //去掉字符串两端空格 System.out.println(s6.trim()); } }