2016-08-11 93 views
-3

我们不得不更换如下阿里巴巴网站的中国比较最佳替代阵列 {}是{4}线上{3}购物{} {}中-positional更换数组索引参数数组字符串格式化在Java中与尖字符串元素

输出必须是阿里巴巴最好的在线比较购物网站在China.Please帮助我变得如此

+5

..........什么? – resueman

+0

使用[编辑]选项来阐明你的问题。也许发布输入和预期结果的例子会有所帮助。 – Pshemo

+0

这是什么?试图说你需要在String中定位这些数组元素?讲清楚 –

回答

1

可以使用的MessageFormat这样

public static void main(String args[]) throws Exception{ 
    String result = MessageFormat.format("{0} is {4} online {3} shopping {1} in {2}" , 
      "Alibaba" ,"site", "china", "comparison", "best"); 
    System.out.println(result); 
} 

它将输出

Alibaba is best online comparison shopping site in china 
0

您需要使用MessageFormat并附加参数要创建味精..

实施例:

public static void main(String[] args) { 

    String msgRaw = "Alibaba {0} {1} site {2} China"; 
    String[] appender = { "is the best", "online comparison shopping", "in" }; 
    String text = MessageFormat.format(msgRaw, appender); 
    System.out.println(text); 
} 

输出

阿里巴巴是中国最好的在线比较购物网站