Sting和StringBuilder数据类型

package cn.jun;

public class StringDemo {
	
/*	public static void main(String[] args) {
		
		StringBuilder x = new StringBuilder("A");
		StringBuilder y = new StringBuilder("B");
		
		chang(x,y);
		System.out.println(x + "." + y);
	}

	private static void chang(StringBuilder x, StringBuilder y) {
		
		x.append(y);//append方法会把字符串追加到该字符串的系列
		y=x;//不会改变的字符串
		
	}*/
	
	public static void main(String[] args) {
		
		String x = new String("A");
		String y = new String("B");
		
		chang(x,y);
		System.out.println(x+"."+y);
	}

	private static void chang(String x, String y) {
		
		x = x + y;
		x = "C";  //String是不可以变的,包括字符串和字符串长度
	}
	
}

猜你喜欢

转载自blog.csdn.net/chenzuen113113/article/details/80002966
今日推荐