字符串.

package pro;

public class pro2 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String s3="123456";
		char s22[]={'1','2','3','4'};
		String s33="12233";
		char c1;
		c1=s33.charAt(2);//
		System.out.println(c1);
		System.out.println(s33.compareTo(s3));//输出第一个不相同的字符的ASCLL码差值
		System.out.println(s3.concat(s33));//链接字符串
		char c[]={'1','2','3','4'};
		System.out.println(String.copyValueOf(c)); //数组转字符串
		System.out.println(s3.equals(s22)); //比较字符串
		String s1="hello";
		s1.getChars(1,3,s22,1);//起,止,目标数组,开始时覆盖位置
		System.out.println(s22);
		System.out.println();
		s1="hello";
		System.out.println(s1.indexOf("he"));//he 第一次出现的位置
		System.out.println(s1.length());//字符串长度
		System.out.println(s1.regionMatches(1, "hello", 0, 5));//检查两个字符串域是否相等
		System.out.println(s1.replace("ah", "a"));//将ah转换为a
		System.out.println(s1);
		System.out.println(s1.startsWith("a,1"));//检测字符串是否以给定的字符开头
		System.out.println();
		String id=("nishisheinishinishi");
		System.out.println(id.substring(6,10));//产生一个子字符串
		System.out.println(id.substring(10,12));
		System.out.println(id.substring(12,14));
		char d[]=s1.toCharArray();
		System.out.println(d.length);
		System.out.println(s1.toUpperCase());
		System.out.println(s1);
		
		StringBuffer s2=new StringBuffer();
		System.out.println(s2);
		System.out.println(s2.length());
		System.out.println(s2.capacity());
		s2.insert(0,"hello,java,hello,java");
		System.out.println(s2);
		System.out.println(s2.length());
		System.out.println(s2.capacity());
	}

	
}

package pro;

public class pro1 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		StringBuffer s1= new StringBuffer();
		s1.append("Hello,Java!");
		System.out.println("s1="+s1);
		StringBuffer s2=new StringBuffer(10);
		s2.insert(0, "Hello,Java1");
		System.out.println("s2="+s2);
		StringBuffer s3=new StringBuffer("Hello,Java!");
		System.out.println("s3="+s3);
	}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值