API常用类库之一String的基本作用介绍

/**
 * 
 */
package cm.string;
/**
 * @author 这个类用来测试String的使用
 *
 */
public class Test1_String2 {
	/**
	 * 
	 */
	public Test1_String2() {
		// TODO Auto-generated constructor stub
	}
	/**日常小黄线:The value of the local variable string is not unused;
	 * 日常小注解:Add @SuppressWarnings 'unused' to main();*/
	public static void main(String[] args) {
		String s = "woaini";
		char c = s.charAt(0);
		System.out.println(c);
		int i = c;
		System.out.println(i);
		
		char[] t = {'冲', '夏', '天'};
		String string = new String(t);
		System.out.println(string);
		char h = string.charAt(1);
		System.out.println(h);
		
		char[] str = new char[] {'勇', '敢', '前', '进'};
		String ing = new String(str);
		string = string.concat(ing);
		System.out.println(string);
		
		String boy = new String(str);
		System.out.println(boy);
		char[] rr = new char[] {'白', '色', '风', '车'};
		String ss = new String(rr);
		ss = boy.concat(ss);
		boy = ss.concat(boy);
		System.out.println(ss);
		System.out.println(boy);
		
		System.out.println(boy.contains(ss));
		System.out.println(boy.equals(ss));
		System.out.println(boy.endsWith("进"));
		System.out.println(string);
		System.out.println(string.equals("冲夏天勇敢前进"));
		
		byte[] b = boy.getBytes();
		System.out.println(b);
		System.out.println(b[0]);
		
		char[] q = {'f', 'd', 'a', 's'};
		String n = new String(q);
		System.out.println(n);
		byte[] w = n.getBytes();
		System.out.println(w);
		System.out.println(w[0]);
		for(int e = 0; e<w.length; ++e) {  //Arrays.toString(数组);
			System.out.print(w[e] + "、");
		}
		
		System.out.println();  //换行
		
		//String类中的hashCode()源码:返回此字符串的哈希码。
		System.out.println(n.hashCode());
		
		System.out.println(n.getBytes());  //数组对象地址值:[B@2ed94a8b
		System.out.println(w);  //byte数组w的地址值[B@73f792cf
		
		System.out.println(n.isEmpty());
		
		System.out.println(n.indexOf("as"));
		System.out.println(n.indexOf("s"));
		System.out.println(n.lastIndexOf("sis"));
		System.out.println(n.length());
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值