本帖最后由 ㏒假™面具 于 2015-3-9 22:45 编辑
- /**
- * String和StringBuffer作为形式参数的问题
- */
- package cn.itcast_02;
- /**
- * @author 面具
- *
- */
- public class StringBufferDemo {
- public static void main(String[] args) {
- String s1 = "Hello";
- String s2 = "World";
- System.out.println(s1 + "---------" + s2);
- change(s1, s2);
- System.out.println(s1 + "---------" + s2);
- StringBuffer sb1 = new StringBuffer(s1);
- StringBuffer sb2 = new StringBuffer(s2);
- System.out.println(sb1 + "-------------" + sb2);
- change(sb1, sb2);
- System.out.println(sb1 + "-------------" + sb2);
- }
- /**
- * @param sb1
- * @param sb2
- */
- public static void change(StringBuffer sb1, StringBuffer sb2) {
- // TODO Auto-generated method stub
- sb1 = sb2;
- sb2.append(sb1);
- }
- /**
- * @param s1
- * @param s2
- */
- public static void change(String s1, String s2) {
- s1 = s2;
- s2 = s1 + s2;
- }
- }
- /*
- * 结果为: Hello---------World Hello---------World Hello-------------World
- * Hello-------------WorldWorld
- */
复制代码
|
|