Problem 1:
public class A {
public void decorate(
String s) {
s = new String("#" + s + "#");
}
public static void main(String[] args) {
A a = new A();
String greeting = "hello";
a.decorate(greeting);
System.out.println(greeting);
}
}
Here is the output is "hello".I can understand why.
Problem 2:
public class A {
public void decorate(List list) {
String s = new String("#");
list.add(s);
}
public static void main(String[] args) {
A a = new A();
List list = new ArrayList();
a.decorate(list);
// This prints the objects in the list
system.out.println(list);
}
}
The output is "#".Can somebody explain why??