Java – wrap another string around the string

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
分享
二维码
< <上一篇
下一篇>>