Java String Reverse reverse(String text)

Here you can find the source of reverse(String text)

Description

reverse

License

Mozilla Public License

Declaration

public static String reverse(String text) 

Method Source Code

//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);
    }
}

Related

  1. compareVersion(String va, String vb)
  2. getReverseShelfKey(String shelfkey)
  3. reverse(String aPackage)
  4. reverse(String s)
  5. reverse(String word)
  6. reverseCommaDelimitedString(final String string)
  7. reverseDelimited(String str, char separatorChar)
  8. reverseUseSB(String str)