字符串变形:比如"Hello World"变形后就变成了"wORLD hELLO", list逆序Collections.reverse(strList)
![](https://img2022.cnblogs.com/blog/608798/202211/608798-20221110172724208-1851383632.png)
import java.util.*;
public class Solution {
public String trans(String s, int n) {
String[] strArray = s.split(" ");
List<String> strList = Arrays.asList(strArray);
Collections.reverse(strList);
StringBuffer sb = new StringBuffer();
for(int i=0; i<strList.size(); i++){
char[] tmp = strList.get(i).toCharArray();
for(int j=0; j<tmp.length; j++){
if(Character.isLowerCase(tmp[j])){
sb.append(Character.toUpperCase(tmp[j]));
}
if(Character.isUpperCase(tmp[j])){
sb.append(Character.toLowerCase(tmp[j]));
}
}
if(i!=strList.size()-1){
sb.append(" ");
}
}
if(s.startsWith(" ")){
sb.append(" ");
return sb.toString();
}
if(s.endsWith(" ")){
return " "+sb.toString();
}
return sb.toString();
}
}