java string reverse

Solutions on MaxInterview for java string reverse by the best coders in the world

showing results for - "java string reverse"
Felipe
16 Feb 2018
1public class ReverseString {
2    public static void main(String[] args) {
3        String s1 = "neelendra";
4        for(int i=s1.length()-1;i>=0;i--)
5            {
6                System.out.print(s1.charAt(i));
7            }
8    }
9}
Frida
18 Jan 2017
1// Library approach
2public static String solution(String str) {
3	// StringBuilder is not thread-safe, use StringBuffer
4	return new StringBuffer(str).reverse().toString();
5}
6
7// DIY approach
8public static String solution(String str) {
9	char[] chars = str.toCharArray();
10	for(int i = 0, j = str.length() - 1; i < j; i++, j--) {
11		char ch = chars[i];
12		chars[i] = chars[j];
13		chars[j] = ch;
14	}
15	return new String(chars);
16}
Giorgio
11 May 2019
1String str = "Hello";
2String reverse(String str){
3  StringBuilder sb = new StringBuilder();
4  sb.append(str);
5  sb.reverse();
6  return sb.toString();
7}
Ryan
04 Oct 2020
1String rev = new StringBuilder("Your String").reverse().toString();
Pedro
08 Jun 2017
1String str = "Reverse this strings";
2//for loop
3for (int i = str.length() - 1; i >= 0; i--) {
4	System.out.print(str.charAt(i));
5}
6
7// StringBuffer for multi thread
8StringBuffer sb = new StringBuffer(); 
9sb.append(str);
10System.out.print(sb.reverse().toString());
11
12// StringBuffer for single thread
13StringBuilder sb = new StringBuilder(); 
14sb.append(str);
15System.out.print(sb.reverse().toString());
Gracelyn
29 Jan 2019
1// reverse a string using character array
2class ReverseUsingCharacterArray
3{
4   public static void main(String[] args)
5   {
6      String str = "HelloWorldJava";
7      char[] ch = str.toCharArray();
8      for(int a = ch.length - 1; a >= 0; a--)
9         System.out.print(ch[a]);
10   }
11}
queries leading to this page
string reverse in javajava program for reverse stringjava string reversed 28 29reverse the string in javaoutput reverse text javareverse string in jjavastring reverse javareverse stringreverse string inbuilt function in javareverse strings javareverse in javarevrser string in javajava string reverseejav string reversejava string reverse programreverse string in java funreverse fuction in string in javastring reverse in javareverse all letters in a string javajava reverse stringinbuilt function to reverse string in javajava string reverse functionreverse a string in java using reverse methodjava make a method that reverse a string reverse a string without using string function in javajava string reverserevese string javahow to print string backwards javastrgin reversehow to print words backwards in javahow to reverse string in javareverse a string in javareverse string array javajava reverse a stringhow to reverse substring javajava prog for string reversereverse string in java functionjava reverse functionreversing string in java how does reversing of a string nd then revrsing of the letters of the reversed string can be done in javahow to make a string display back to front javareversing a string in javareverse string method javareverse letters of a string in javareverse an string in javahow to get backward of string javajava api reverse stringrevserse string in javajav reverse stringrevert string in javafor given string return a new string 2awith the reversed order of charactersreturn a string in reverse order javareverse a word in string in javahow to reverse string in javareverse a string array javastirng reverse javastring reversejava how to reverse a stringreversing character array in javahow to display a string backwards in javareverse string javahow to flip a string in javareverse string function in javahow to write a reverse methodsololearn reverse a string javajava invert stringjava string array reverse methodhow to get reverse of string in java using inbuilt functionhow to reverse string javastring reverse javahow to write string reverse in javareverse output javareverse a string javabest way to reverse a string in javahow to print an input backwards in javareversing the string fuction javahow to reverse a string in java using methodstring rev in javahow to write a reverse method in javareverse of a string in javawap to reverse a string using the inbuilt reverse 28 29 method in javastring reverse method in javajava reversing a stringprint string in reverse order javareverse method in java for stringshow to reverse a string in javareverse print a string in javajava program to reverse a stringreverse string using javaprogram to print reverse string in javareverse method in javareverse string in javajava method to reverse a stringreverse function a string in javajava string reverse codereverse of string in javainvert a string java codereverse a string in java non void functionhow to reverse a string in java with using reverse functionreverse string java charat 28 29how to write string reverse program in javahow to invert string in javajava string reversereverse strin javastring rervese javajava reverse string using for loopreverse char array javahow to rever string in javajava string reverse