Languages
[Edit]
EN

Java - how to reverse a string

0 points
Created by:
Dirask Admin - Marwin
1430

In this article, we would like to show you how to reverse a string in Java.

Practical example

In the example below, we use the reverse() method that we can execute on an instance of the StringBuilder class.

public class StringExample {

    public static void main(String[] args) {
        String originalString = "This is your text...";
        String reversedString = new StringBuilder( originalString ).reverse().toString();

        System.out.println( reversedString ); // ...txet ym si sihT
    }
}

Output:

...txet ym si sihT

Java - String (popular problems)

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join