在没有连接的情况下将Java字符串插入另一个字符串? [英] Inserting a Java string in another string without concatenation?

查看:57
本文介绍了在没有连接的情况下将Java字符串插入另一个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中有更优雅的方法吗?

Is there a more elegant way of doing this in Java?

String value1 = "Testing";  
String test = "text goes here " + value1 + " more text";

是否可以将变量直接放在字符串中并评估其值?

Is it possible to put the variable directly in the string and have its value evaluated?

推荐答案

   String test = String.format("test goes here %s more text", "Testing");

是你用Java写的最接近的东西

is the closest thing that you could write in Java

这篇关于在没有连接的情况下将Java字符串插入另一个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆