Java - Write code to reverse String via its char array

Requirements

Write code to reverse String via its char array

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String s = "book2s.com";
        System.out.println(reversString(s));
    }/*  w ww  . j  ava2s . c  om*/

    public static String reversString(String s) {
        char[] arr = s.toCharArray();
        int end = s.length();
        end = end - 1;
        int start = 0;
        while (start < end) {
            char temp = arr[start];
            arr[start] = arr[end];
            arr[end] = temp;
            start++;
            end--;
        }

        return String.copyValueOf(arr);
    }
}

Related Exercise