Groovy supports string interpolation operations. Here is an example
def name = "Tom"
println("Hello my name is ${name}")
Does Java 8 support string interpolation as the way Groovy does?
Any answer, greatly appreciated. Thanks
Java8 has nothing to do with this. For formatted console output, you can use printf()
or the format()
method of System.out
Try this out.
System.out.printf("My name is: %s%n", "Tom");
For formatted console output use of String.format is recommanded. System.out.println(String.format("My name is: %s%n", "Tom"));
When logging a message there are several important requirements which must be fulfilled:
That's why defining and using a dedicated logger is highly recommended. org.slf4j.Logger is one of the standard Logger factory and is easy to use.
private static final Logger LOGGER = LoggerFactory.getLogger(<ClassName>.class);
LOGGER.info("My name is: {}", "Tom");