有关StringBuilder字符串的一些应用
2016-06-08 18:46
375 查看
1.有关StringBuilder字符串的一些应用
字符串基本Api
a)创建一个String对象("刘德华_java程序员_布鲁明顿"),把它转换为一个char数组,char数组存储String的每一个字符。
b)创建一个StringBuilder对象,把char数组内容添加到StringBuilder对象中
c)删除(第9-11个字符),然后插入字符串"高级攻城狮"到第9个位置
d)再把"java"字符串替换为("ios"),再倒序存储字符串
e)再把字符串都转换为大写,然后输出结果字符串
public class Test1 {
public static void main(String[] args) {
String str="刘德华_java程序员_布鲁明顿";
char[] a=str.toCharArray();
System.out.println(a);
StringBuilder str1=new StringBuilder();
str1.append(a);
System.out.println(str1);
str1.delete(8, 12);
System.out.println(str1);
str1.insert(9, "高级攻城狮");
System.out.println(str1);
str1.replace(4, 8, "ios");
System.out.println(str1);
str1.reverse();
System.out.println(str1);
String str2=str1.toString();
str2=str2.toUpperCase();
System.out.println(str2);
}
}
字符串基本Api
a)创建一个String对象("刘德华_java程序员_布鲁明顿"),把它转换为一个char数组,char数组存储String的每一个字符。
b)创建一个StringBuilder对象,把char数组内容添加到StringBuilder对象中
c)删除(第9-11个字符),然后插入字符串"高级攻城狮"到第9个位置
d)再把"java"字符串替换为("ios"),再倒序存储字符串
e)再把字符串都转换为大写,然后输出结果字符串
public class Test1 {
public static void main(String[] args) {
String str="刘德华_java程序员_布鲁明顿";
char[] a=str.toCharArray();
System.out.println(a);
StringBuilder str1=new StringBuilder();
str1.append(a);
System.out.println(str1);
str1.delete(8, 12);
System.out.println(str1);
str1.insert(9, "高级攻城狮");
System.out.println(str1);
str1.replace(4, 8, "ios");
System.out.println(str1);
str1.reverse();
System.out.println(str1);
String str2=str1.toString();
str2=str2.toUpperCase();
System.out.println(str2);
}
}
相关文章推荐
- Looper、Message、MessageQueue、Handler异步消息处理机制源码分析
- 检测预设资源是否有UIFont为空的编辑器
- Android学习之图解调用invalidate()和requestLayout()的过程
- Parquet 读写
- 栈(stack)和队列(queue)的简单实例
- UIAlertController
- UIView的drawRect调用时机和条件
- 栈和队列的简单实例
- RequireJS入门(一)
- BearSkill之UIView挖空处理
- ios UIView常用动画效果
- 关于easyui 行高禁止自适应
- Android中常用的handler进行UI更新和Thread代码
- .MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1
- while(true)引发的Dubbo应用假死
- iOS巅峰之UILabel上显示不同的字体样式和颜色
- UIFont 字体样式 [UIFont fontWithName~];
- libevent windows build
- hdu 1005 Number Sequence(循环节)
- 【EasyUI-扩大在DataGrid显示次网格的行】