Easy way to reverse String

后端 未结 12 1025
野性不改
野性不改 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:31

    Here I have a sample of the same using substring method and o(n) without using any nethods from string . I am aware that using substring will hold complete string memory.

    for(int i = 0; i < s.length(); i++)    {
        s = s.substring(1, s.length() - i) + s.charAt(0) + s.substring(s.length() - i);
        System.out.println(s);
    }
    

    This might help you!!

提交回复
热议问题