You can always use String.format(....). i.e.,
String string = String.format("A String %s %2d", aStringVar, anIntVar);
I'm not sure if that is attractive enough for you, but it can be quite handy. The syntax is the same as for printf and java.util.Formatter. I've used it much especially if I want to show tabular numeric data.
Answer from Hovercraft Full Of Eels on Stack OverflowYou can always use String.format(....). i.e.,
String string = String.format("A String %s %2d", aStringVar, anIntVar);
I'm not sure if that is attractive enough for you, but it can be quite handy. The syntax is the same as for printf and java.util.Formatter. I've used it much especially if I want to show tabular numeric data.
This is called string interpolation; it doesn't exist as such in Java.
One approach is to use String.format:
String string = String.format("A string %s", aVariable);
Another approach is to use a templating library such as Velocity or FreeMarker.
Difference between creating a string object vs a string variable in java ?
The String variable in Java
String[] variable vs String variable[]??? - Processing Forum
I do not understand String and Variables. Are they [String variables] or two different things. Need help to understand.
Videos
I’m trying to understand what the difference is between the two and after an hour of reading around I still do not understand.. could someone dumb this down for me + explain what a string constant pool is + scenario in which you would use either of the two?
String s= "Hello";
s="Hi";
It prints Hi , How that is possible ,I am confused here . Strings are immutable means we cannot change alter the value stored in it . if we change the value then , a new string object will be created with a new memory location
String b=s.replace("Hello","Hey"); This method replaces the string value and stores in new memory location by creating new string object called b .How reassigning of strings are possible ? if Strings are immutable