现在的位置: 首页 > 综合 > 正文

String解析

2018年05月24日 ⁄ 综合 ⁄ 共 364字 ⁄ 字号 评论关闭

String的比较有两种==和equals()方法:

==:比较的是在堆内存中地址

equals():比较的是值

String s1="hello";
String s2="hello";
String s3=new String("hello");

s1==s2;//结果为true
s1==s3;//结果为false
s1.equals(s2);//结果为true
s1.equals(s3);//结果为true

原理图:

String的内容不可改变:

public class StringDemo{
	public static void main(String args[]){
		String str = "hello" ;		// 声明字符串
		str = str + " world!!!"	;	// 修改字符串
		System.out.println("str = " + str) ;
	}
};

原理图:

常用方法:

抱歉!评论已关闭.