Java String Reverse reverse(String s)

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

Description

Reverse a string

License

Apache License

Declaration

public static String reverse(String s) 

Method Source Code

//package com.java2s;
/*-------------------------------------------------------------------------+
|                                                                          |
| Copyright 2005-2011 The ConQAT Project                                   |
|                                                                          |
| Licensed under the Apache License, Version 2.0 (the "License");          |
| you may not use this file except in compliance with the License.         |
| You may obtain a copy of the License at                                  |
|                                                                          |
|    http://www.apache.org/licenses/LICENSE-2.0                            |
|                                                                          |
| Unless required by applicable law or agreed to in writing, software      |
| distributed under the License is distributed on an "AS IS" BASIS,        |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and      |
| limitations under the License.                                           |
+-------------------------------------------------------------------------*/

import java.util.Iterator;

import java.util.Map;

public class Main {
    /** Line break. */
    public static final String CR = System.getProperty("line.separator");
    /** The empty string. */
    public static final String EMPTY_STRING = "";

    /** Reverse a string */
    public static String reverse(String s) {
        return new StringBuilder(s).reverse().toString();
    }//from  w  w  w  . j av a 2s  . co m

    /**
     * Create string representation of a map.
     */
    public static String toString(Map<?, ?> map) {
        return toString(map, EMPTY_STRING);
    }

    /**
     * Create string representation of a map.
     * 
     * @param map
     *            the map
     * @param indent
     *            a line indent
     */
    public static String toString(Map<?, ?> map, String indent) {
        StringBuilder result = new StringBuilder();
        Iterator<?> keyIterator = map.keySet().iterator();

        while (keyIterator.hasNext()) {
            result.append(indent);
            Object key = keyIterator.next();
            result.append(key);
            result.append(" = ");
            result.append(map.get(key));
            if (keyIterator.hasNext()) {
                result.append(CR);
            }
        }

        return result.toString();
    }
}

Related

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