Yahoo India Web Search

Search results

  1. 5 days ago · Reverse a string in Java - GeeksforGeeks. Last Updated : 26 Jun, 2024. This article discusses different ways to reverse a string in Java with examples. Examples: Prerequisite: String vs StringBuilder vs StringBuffer in Java. Following are some interesting facts about String and StringBuilder classes : Objects of String are immutable.

  2. Jan 25, 2024 · Reverse a String. Solve Problem. Reverse String using a Loop: Initialize an empty string to store the reversed result. Iterate through the original string in reverse order. Append each character to the new string. The new string is the reversed version of the original string.

  3. Reverse a String. You can easily reverse a string by characters with the following example: Example. String originalStr = "Hello"; String reversedStr = ""; for (int i = 0; i < originalStr.length(); i++) { . reversedStr = originalStr.charAt(i) + reversedStr; } System.out.println("Reversed string: "+ reversedStr); Try it Yourself »

  4. Mar 5, 2024 · Reverse the String Using Library Function. In C, we have a library function defined inside <string.h> that can be used to reverse a string. The strrev() function provides the simplest method to reverse the string. Syntax char* strrev(char* str); where, str is the string to be reversed.

  5. Reverse String. Easy. Write a function that reverses a string. The input string is given as an array of characters s. You must do this by modifying the input array in-place with O(1) extra memory. Example 1: Input: s = ["h","e","l","l","o"] Output: ["o","l","l","e","h"] Example 2: Input: s = ["H","a","n","n","a","h"]

  6. How to reverse String in Java. There are many ways to reverse String in Java. We can reverse String using StringBuffer, StringBuilder, iteration etc. Let's see the ways to reverse String in Java. 1) By StringBuilder / StringBuffer. File: StringFormatter.java

  7. Sep 10, 2017 · You can use this: new StringBuilder(hi).reverse().toString() StringBuilder was added in Java 5. For versions prior to Java 5, the StringBuffer class can be used instead — it has the same API. edited Oct 13, 2021 at 22:08. M. Justin. 18.5k 9 114 145. answered Sep 27, 2011 at 12:47.

  1. People also search for