字符串反转

import java.util.ArrayList;
import java.util.List;

public class User  {
public String reverse(List str){
        StringBuilder sb = new StringBuilder();
        String ss = str.get(0);
        String[] lines = ss.split("\\.");
        int len = lines.length;

        for (int i = len-1;i>=0;i--) {
           sb.append(lines[i]);
           sb.append(".");
        }
        return sb.toString();
    }

    public static void main(String[] args){
        User user = new User();
        List str = new ArrayList();
        str.add("com.job.www");
        String result = user.reverse(str);
        System.out.println(result);
    }

题目要求:一个List中存放着字符串com.job.www,按点分割,然后反转字符串。

你可能感兴趣的:(java)