String字符串常用方法
String str=" abcde f@g ";
//字符串长度
System.out.println(str.length());
//字符串转换数组
char [] data=str.toCharArray();
System.out.println(data);
//从字符串中取出指定位置的字符
System.out.println(str.charAt(0));
//字符串与byte数组的转换
byte [] bytes=str.getBytes();
System.out.println(bytes);
System.out.println(new String(bytes));
//过滤字符串中存在的字符
System.out.println(str.indexOf("@"));
//去掉字符串中前后空格
System.out.println(str.trim());
//大小写转换
System.out.println(str.toLowerCase());
System.out.println(str.toUpperCase());
//判断字符串的开头和结尾字符
str.startsWith("abc");
str.endsWith("ed");
//返回一个新的字符串,它是通过用 newChar 替换此字符串中出现的所有 oldChar 得到的。
str=str.replace('a','b');
System.out.println(str);
还没有评论,来说两句吧...