synchronized (new Object()) {
String word = "hello";
String result = "";
for (int k = word.length() - 1; k >= 0; k--) {
// 无效率,别这么做
// 每一轮都会创建新的String对象并舍弃旧的,可以使用StringBuffer或者StringBuilder
// result = result + String.format("%s", word.charAt(k));
result = result + word.substring(k, k+1);
// System.out.println(word.substring(k, k + 1));
}
System.out.println(result);
}
网友评论