【Java开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了Java开源代码-charCmd.java的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
public class charCmd
{
public static void main(String[] args)
{
//初始化两个字符数组C1和C2
char [] c1={'I','a','m','a','b','o','y'};
char [] c2={'h','e','i','s','a','b','b','y'};
//利用这两个字符数组构造两个字符串对象x和y,并且将其输出
String x=new String(c1);
String y=new String(c2);
System.out.println(x);
System.out.println(y);
//将字符串x构成成一个缓冲字符串对象temp
StringBuffer temp= new StringBuffer(x);
//使用append方法将y与x连在一起,并且将其输出
temp.append(y);
System.out.println(temp);
//提取某个charAt方法位置上的元素
System.out.println(temp.charAt(0));
temp.setCharAt(0, 'y');
temp.insert(1, 'o');
temp.insert(2, 'u');
System.out.println(temp);
System.out.println(temp.substring(7));
//使用reverse方法将字符串倒置,并且将其输出
temp.reverse();
System.out.println(temp);
}
}