SummerVocation_Learning--String 类

    java中String属于java.lang的package包,是一个类。代表不可变的字符序列。

    String类的常见构造方法:

            String(String original),创建一个对象为original的拷贝。

            String(char[] value),用一个字符数组创建一个String对象。

            String(char[] value,int offset,int count),用一个数组从offset项开始的count个字符序列创建一个String对象。

    举例1:

public class TestString {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String s1 = "hello",s2 = "world";
		String s3 = "hello";
		System.out.println(s1==s3); //判断s1,s3是否相等。输出true。
		
		s1 = new String("hello");
		s2 = new String("hello");
		System.out.println(s1==s2); //false
		System.out.println(s1.equals(s2)); //true
		
		char[] c= {'h','e','l','l','o',',','w','o','r','l','d'};
		String s4 = new String(c);
		String s5 = new String(c, 6, 5);
		System.out.println(s4); //hello,world
		System.out.println(s5); //world
	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值