[TOC]
```java
public class T {
public static void main(String[] args) {
//demo1
String str = new String("hello");
char[] chars = {'w','o','r','l','d'};
change(str,chars);
System.out.println(str+" "+new String(chars));
//demo2
StringBuffer sb=new StringBuffer("hello");
change(sb);
System.out.println(sb);
//demo2
StringBuffer a = new StringBuffer("A");
StringBuffer b = new StringBuffer("B");
operate(a,b);
System.out.println(a+"."+b);
}
public static void change(String str, char[] chars){
str = str.replace('h','H');
chars[0]='W';
}
public static void change(StringBuffer sb){
sb.append(" world");
}
private static void operate(StringBuffer a, StringBuffer b) {
a.append(b);
b=a;
}
}
```
运行结果
```
hello World
hello world
AB.B
```
参考文章
> https://blog.csdn.net/u013309870/article/details/75499175