How To Reverse A String In Java

[Solved] How To Reverse A String In Java | Scala - Code Explorer | yomemimo.com
Question : how to reverse a string in java

Answered by : annoying-anaconda

public class ReverseString { public static void main(String[] args) { String s1 = "neelendra"; for(int i=s1.length()-1;i>=0;i--) { System.out.print(s1.charAt(i)); } }
}

Source : https://stackoverflow.com/questions/7569335/reverse-a-string-in-java | Last Update : Sat, 21 Mar 20

Question : reverse a string in java

Answered by : ahmad-mujtaba

public class StringReverseExample{ public static void main(String[] args) { String string = "abcdef"; String reverse = new StringBuffer(string).reverse().toString(); System.out.println("\nString before reverse: "+string); System.out.println("String after reverse: "+reverse); }
}

Source : https://www.tutorialspoint.com/javaexamples/string_reverse.htm | Last Update : Fri, 27 Aug 21

Question : string reverse in java

Answered by : lonely-lark-mc835iuchiml

String str = "Hello";
String reverse(String str){ StringBuilder sb = new StringBuilder(); sb.append(str); sb.reverse(); return sb.toString();
}

Source : | Last Update : Sat, 16 May 20

Question : Reverse a String in Java

Answered by : itchy-impala-xqthyfykiqkk

public class ReverseStringByFavTutor
{ public static void main(String[] args) { String stringExample = "FavTutor"; System.out.println("Original string: "+stringExample); // Declaring a StringBuilder and converting string to StringBuilder StringBuilder reverseString = new StringBuilder(stringExample); reverseString.reverse(); // Reversing the StringBuilder // Converting StringBuilder to String String result = reverseString.toString(); System.out.println("Reversed string: "+result); // Printing the reversed String }
}

Source : https://favtutor.com/blogs/reverse-string-java | Last Update : Mon, 31 Jan 22

Question : String reverse in java

Answered by : radamel-falcao

1)
String str = "Hello";
String result = ""; for(int i = str.length()-1; i>=0; i--){ result += str.charAt(i); // first solution, charAt method // result += str1.substring(i, i+1); // first solution, substring method } System.out.println(result);
}

Source : | Last Update : Fri, 11 Jun 21

Question : reverse a string in java

Answered by : bradley-b

// Not the best way i know but i wanted to challenge myself to do it this way so :)
public static String reverse(String str) { char[] oldCharArray = str.toCharArray(); char[] newCharArray= new char[oldCharArray.length]; int currentChar = oldCharArray.length-1; for (char c : oldCharArray) { newCharArray[currentChar] = c; currentChar--; } return new String(newCharArray);
}

Source : | Last Update : Thu, 18 Feb 21

Question : java reverse string

Answered by : travinth-dayalaeaswaran

// java program to reverse a word
  
import java.io.*;
import java.util.Scanner;
  
class GFG {
    public static void main (String[] args) {
        
        String str= "Geeks", nstr="";
        char ch;
        
      System.out.print("Original word: ");
      System.out.println("Geeks"); //Example word
        
      for (int i=0; i<str.length(); i++)
      {
        ch= str.charAt(i); //extracts each character
        nstr= ch+nstr; //adds each character in front of the existing string
      }
      System.out.println("Reversed word: "+ nstr);
    }
}
  
//Contributed by Tiyasa

Source : https://www.geeksforgeeks.org/reverse-a-string-in-java/ | Last Update : Tue, 19 Jul 22

Question : String reverse in Java

Answered by : radamel-falcao

StringBuilder sb1 = new StringBuilder("Mahmut"); sb1.reverse(); System.out.println(sb1); // tumhaM

Source : | Last Update : Wed, 16 Jun 21

Answers related to how to reverse a string in java

Code Explorer Popular Question For Scala