java

To Reverse A String: StringBuffer in Java

Java provides the StringBuffer and String classes. The String class is used to manipulate character strings that cannot be changed. To put it simply: objects of type String are read only and immutable.

The StringBuffer class is used to represent characters that cannot be modified.

The significant performance between these two classes is that the StringBuffer is remarkably faster than the String when performing simple concatenations.

Using the String class, we can concatenate as follows:

String str = new String("Lawson ");
str += "Luke";

With String Buffer

StringBuffer strBuff = new StringBuffer("Lawson ");
strBuff.append("Luke");

To reverse a String …

public class StringReverse{
public static void main(String args[]){
String str = new String("Luke");
StringBuffer buff = new StringBuffer(str);
System.out.println(buff.reverse());
}
}

Recent Posts

Compiler vs Interpreter — When to Choose What

At the heart of every programming language lies a crucial question: how does human-readable code become…

8 hours ago

The Third Industrial Revolution (The Digital Revolution)

The Third Industrial Revolution refers to the transformative period in which digital technologies replaced analog and mechanical…

22 hours ago

Linux Steam Locomotive Bash program

What is Steam Locomotive (sl)? Steam Locomotive (sl) is a small terminal program on Unix/Linux systems…

3 weeks ago

Rate Limiting in Node JS

What is Rate Limiting? Download this article as a PDF on the Codeflare Mobile App…

4 weeks ago

JavaScript promise chaining

Learn on the Go. Download the Codeflare Mobile from iOS App Store.  1. What is…

1 month ago

UI/UX Design — Explained Like You’re 5

Download the Codeflare iOS app and learn on the Go 1. What UI and UX…

2 months ago