I have a class in theFirst.java
file.
public class theFirst {
private String str = "Hello , i'm here";
public IntStream get_code_point(){
return str.codePoints();
}
public void str_print(){
System.out.println(str);
}
public String get_str(){
return str;
}
}
In another class in for_test.java
, I want to get a string to add something to it and have it change too:
public class for_test {
public static void main(String[] args){
theFirst tmp = new theFirst();
String test2 = tmp.get_str();
test2+= "another one";
tmp.str_print();
System.out.println(test2);
}
}
But for some reason, when called tmp.str_print();
. The line has not changed, but if i print
System.out.println(test2);
then prints the modified one.
I am new to java and as I understand such classes should pass a reference, but as I understand copying occurs.I'll be glad if you can help me figure it out.