Here you can find the source of invertString(String s)
Parameter | Description |
---|---|
s | The String to reverse. |
public static String invertString(String s)
//package com.java2s; //License from project: Open Source License public class Main { /**/* w w w.ja va 2s . co m*/ * Reverse a given String. * * @param s The String to reverse. * @return The reversed string. */ public static String invertString(String s) { if ((s == null) || (s == "")) return ""; byte[] b = s.getBytes(); byte[] c = new byte[b.length]; int x = b.length; for (int i = 0; i < x; i++) c[x - i - 1] = b[i]; return new String(c); } }