Easy way to reverse String

后端 未结 12 1270
野性不改
野性不改 2021-02-13 04:01

Without going through the char sequence is there any way to reverse String in Java

12条回答
  •  余生分开走
    2021-02-13 04:29

    If we have to do it:

    Without going through the char sequence

    One easy way with iteration will be:

    public String reverse(String post) {                
        String backward = "";
        for(int i = post.length() - 1; i >= 0; i--) {
            backward += post.substring(i, i + 1);
        }        
        return backward;
    } 
    

提交回复
热议问题