Exercism v3 launches on Sept 1st 2021. Learn more! ๐Ÿš€๐Ÿš€๐Ÿš€
Avatar of rootulp

rootulp's solution

to Reverse String in the Java Track

Published at Apr 26 2020 · 0 comments
Test suite

Reverse a string

For example: input: "cool" output: "looc"


For more help on how to solve this exercise, please refer to the tutorial provided as part of the hello world exercise: TUTORIAL.md


Go through the setup instructions for Java to install the necessary dependencies:


Running the tests

You can run all the tests for an exercise by entering the following in your terminal:

$ gradle test

In the test suites all tests but the first have been skipped.

Once you get a test passing, you can enable the next one by removing the @Ignore("Remove to run test") annotation.


Introductory challenge to reverse an input string https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.


import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class ReverseStringTest {

    public void testAnEmptyString() {
        assertEquals("", new ReverseString().reverse(""));

    @Ignore("Remove to run test")
    public void testAWord() {
        assertEquals("tobor", new ReverseString().reverse("robot"));

    @Ignore("Remove to run test")
    public void testACapitalizedWord() {
        assertEquals("nemaR", new ReverseString().reverse("Ramen"));

    @Ignore("Remove to run test")
    public void testASentenceWithPunctuation() {
        assertEquals("!yrgnuh m'I", new ReverseString().reverse("I'm hungry!"));

    @Ignore("Remove to run test")
    public void testAPalindrome() {
        assertEquals("racecar", new ReverseString().reverse("racecar"));

    @Ignore("Remove to run test")
    public void testAnEvenSizedWord() {
        assertEquals("reward", new ReverseString().reverse("drawer"));
class ReverseString {

    String reverse(String inputString) {
    	StringBuilder builder = new StringBuilder(inputString);
    	return builder.reverse().toString();


Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other peopleโ€™s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?