Here you can find the source of reverse(String text)
public static String reverse(String text)
//package com.java2s; /** This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. *///from w w w. j a va2 s. c o m import java.util.*; public class Main { public static String reverse(String text) { //e.g. from "ABC" to "CBA" char[] chars = text.toCharArray(); ArrayList<Character> list = new ArrayList<>(); for (int i = chars.length - 1; i >= 0; i--) { list.add(chars[i]); } int size = list.size(); chars = new char[size]; for (int i = 0; i < size; i++) { chars[i] = list.get(i); } return new String(chars); } }