Since, In Java, Strings are implemented as references of type Object
.Also, String constants
are implemented as Objects.
For eg:
System.out.println("This is a String");
In the above statement, "This is a String" is also implemented as type Object. This means it will be allocated memory which would be same as
String str = "This is a String";
My question is What if i print multiple Strings using +
operator in the same System.out
statement like this,
System.out.println("This is a String" + "This is another String");
Now, What I'm basically asking is that I want to know if "This is a String"
and "This is another String"
will take up different memory spaces or Same memory space??
Also, does addition of a variable between the Strings in println()
statement make a difference?
For eg:
int i = 10;
System.out.println("This is a String" + i + "This is another String");
Other questions related to strings on this site don't answer my question specifically.Please put a light on this question ^_^
Any help would be appreciated