String:反转字符串

public static String test1(String string) {
        char[] strAry = string.toCharArray();
        int i = 0;
        int j = strAry.length - 1;
        while (i < j) {
            char temp = strAry[i];
            strAry[i] = strAry[j];
            strAry[j] = temp;
            i++;
            j--;

        }
        String string2 = new String();
        for (int j2 = 0; j2 < strAry.length; j2++) {
            string2 += strAry[j2];

        }

        return string2;
    }

你可能感兴趣的:(String:反转字符串)