reverse a String without using StringBuilder - Java java.lang

Java examples for java.lang:String Algorithm

Description

reverse a String without using StringBuilder

Demo Code


//package com.java2s;

public class Main {
    public static String reverse(String s) {
        String ret = "";
        for (int i = s.length() - 1; i > 0; i--) {
            ret += s.charAt(i);//www .ja  v a2  s.  co  m
        }
        return ret;
    }
}

Related Tutorials