344ReverseString

      注意:String是字面量类型,即封装的字符数组内容不能改变,如要改变,只能重新生成新的字符串;此外,注意,数组下标的使用!


    public String reverseString(String s) { //literal type : String
        int len = s.length();
        char ch[] = s.toCharArray();
        for(int i = 0; i < len/2; i++){
            char tp;
            tp = ch[i];
            ch[i] = ch[len-1-i];
            ch[len-1-i] = tp;
        }
        //System.out.println(""+ s.charAt(0)+" "+ ch[0]);
        String rt = new String(ch);
        return rt;
    }

你可能感兴趣的:(String,array)