---
title: "What is the finest method to recursively reverse a string in Java?"  
description: "What is the finest method to recursively reverse a string in Java?"  
author: "Anonymous User"  
published: 2013-10-04  
updated: 2013-10-04  
canonical: https://www.mindstick.com/forum/1577/what-is-the-finest-method-to-recursively-reverse-a-string-in-java  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# What is the finest method to recursively reverse a string in Java?

I have been messing around with [recursion](https://answers.mindstick.com/qa/111681/what-is-recursion-and-when-should-i-use-it) today. [Often](https://answers.mindstick.com/qa/115859/how-do-i-resolve-the-we-limit-how-often-you-can-do-certain-things-error) a [programming](https://www.mindstick.com/articles/12214/web-development-company-in-india-laid-on-the-foundation-of-concrete-java-programming) [technique](https://answers.mindstick.com/qa/93922/why-c-sharp-programmers-use-properties-technique-in-c-sharp-programming) that is not used enough.

I set out to recursively [reverse](https://www.mindstick.com/blog/63740/what-are-the-most-effective-and-safest-thanks-to-reverse-erectile-dysfunction) a [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp). Here's what I [came up](https://answers.mindstick.com/qa/41115/who-came-up-with-the-10-percent-plan-what-did-this-plan-say) with:

```
public String reverseString(String s){
        char c = s.charAt(s.length()-1);
        if(s.length() == 1) return Character.toString(c);
        return c + reverseString(s.substring(0,s.length()-1));
    }
```

\

## Replies

### Reply by Anonymous User

The finest way is not to use recursion. These stuff are usually used to teach students the recursion concept, not actual best practices. So the way you're doing it is just fine. Just don't use recursion in Java for these kind of stuff in real world apps ;)

PS. Aside what I just said, I'd choose "" as the base case of my recursive function:

\

```
public String reverseString(String s){
    if (s.length() == 0)
         return s;
    return reverseString(s.substring(1)) + s.charAt(0);
}
```

\

\


---

Original Source: https://www.mindstick.com/forum/1577/what-is-the-finest-method-to-recursively-reverse-a-string-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
