字符串的逆序--手写


import org.junit.Test;

public class solution {
    @Test
    public void testFunc(){
        String string = "hello";
        String reString = reverseString(string);
        System.out.println("res: "+reString);
        
    }
    
    
    
//    字符串的逆序
    public String reverseString(String str){
        if (str==null || str.length()<=1) {
            return str;
        }
        char[] charArray = str.toCharArray();
        String res="";
        for(int i =charArray.length-1;i>=0;i--){
            res+=charArray[i];
            
        }
        return res;
    }
    
}

猜你喜欢

转载自blog.csdn.net/wwzheng16/article/details/81023959