Java – wrap another string around the string
•
Java
Do I have any utils methods in Java that allow me to surround a string with another string? It's like:
surround("hello","%");
"Hello%" will be returned. "
I only need one method, so the code will be better, and then add prefixes and suffixes I don't want to have a custom utils class if it's not necessary
Solution
String. Format can be used for this purpose:
String s = String. format(“%%% s %%”,“hello”);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码