62,614
社区成员
发帖
与我相关
我的任务
分享
String testStr = "aaacwwqe";
int pos1 = 1;
int pos2 = 5;
char [] charArray = testStr.toCharArray();
char tempStr = charArray[pos1-1];
charArray[pos1-1] = charArray[pos2-1];
charArray[pos2-1] = tempStr;
StringBuilder stb = new StringBuilder();
for (char ch:charArray) {
stb.append(String.valueOf(ch));
}
System.out.println("The replace string is:" + stb.toString());