楼上的各位说的很正确,我替你们把代码写下来。public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String str = "Hello World This is just a test";
String[] temp = str.split(" ");
String[] newStrings = new String[temp.length];
for (int i = 0; i < temp.length; i++) { newStrings[i] = temp[temp.length - i - 1]; }
for (int i = 0; i < newStrings.length; i++) { System.out.print(newStrings[i] + " "); }
而不能达到 “world hello” 的效果
再从后遍历,组合起来.
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub String str = "Hello World This is just a test";
String[] temp = str.split(" ");
String[] newStrings = new String[temp.length];
for (int i = 0; i < temp.length; i++) {
newStrings[i] = temp[temp.length - i - 1];
}
for (int i = 0; i < newStrings.length; i++) {
System.out.print(newStrings[i] + " ");
}
}}输出:
test a just is This World Hello