reverse a string in java

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

showing results for - "reverse a string in java"
Mila
06 Oct 2018
1// reverse a string using reverse() method of StringBuilder class
2class ReverseUsingReverseMethod
3{
4   public static void main(String[] args)
5   {
6      String str = "Hello world Java";
7      StringBuilder sb = new StringBuilder();
8      // append string to StringBuilder
9      sb.append(str);
10      sb = sb.reverse();
11      // printing reversed String
12      System.out.println(sb);
13   }
14}
Emilie
27 Jan 2017
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}
Maëlle
06 Aug 2016
1Solution 1 
2
3public static String StrReverse(String str) {
4
5String reverse="";
6
7for(int i=str.length()-1; i >= 0; i--)
8
9reverse += str.toCharArray()[i];
10
11 
12
13return  reverse;
14
15}
16
17 
18
19Solution 2 (using string buffer)
20
21public  static String  Reverse(String str) {
22
23return new StringBuffer(str).reverse().toString());
24
25}
Francisco
20 Jan 2021
1public class StringReverseExample{
2   public static void main(String[] args) {
3      String string = "abcdef";
4      String reverse = new StringBuffer(string).reverse().toString();
5      System.out.println("\nString before reverse: "+string);
6      System.out.println("String after reverse: "+reverse);
7   }
8}
Randy
23 Jan 2016
1// reverse a string using toCharArray() method
2class ReverseUsingToCharArrayMethod
3{
4   public static void main(String[] args)
5   {
6      String str = "Hello World Java";
7      char[] chTemp = str.toCharArray();
8      int left, right = 0;
9      right = chTemp.length - 1;
10      for(left = 0; left < right ; left++, right--)
11      {
12         // swap values
13         char temp = chTemp[left];
14         chTemp[left] = chTemp[right];
15         chTemp[right]=temp;
16      }
17      for(char c : chTemp)
18         System.out.print(c);
19      System.out.println();
20   }
21}
Valeria
30 May 2019
1// reverse a string using ByteArray
2class ReverseStringByteArray
3{
4   public static void main(String[] args)
5   {
6      String input = "HelloWorld";
7      // getBytes() method to convert string into bytes[].
8      byte[] strByteArray = input.getBytes();
9      byte[] output = new byte[strByteArray.length];
10      // store output in reverse order
11      for(int a = 0; a < strByteArray.length; a++)
12         output[a] = strByteArray[strByteArray.length - a - 1];
13      System.out.println(new String(output));
14   }
15}
Henry
26 Jun 2020
1// Not the best way i know but i wanted to challenge myself to do it this way so :)
2public static String reverse(String str) {
3  char[] oldCharArray = str.toCharArray();
4  char[] newCharArray= new char[oldCharArray.length];
5  int currentChar = oldCharArray.length-1;
6  for (char c : oldCharArray) {
7    newCharArray[currentChar] = c;
8    currentChar--;
9  }
10  return new String(newCharArray);
11}
Cambria
09 Sep 2019
1public class Main {
2
3    public static void main(String[] args) {
4	// Write a Java program to reverse a string.
5        Scanner input = new Scanner(System.in);
6        System.out.println("Enter the String:");
7        char[] letters = input.nextLine().toCharArray();
8        System.out.println(" Reverse String");
9        for(int i = letters.length -1; i >= 0; i--){
10            System.out.print(letters[i]);
11        }
12    }
13}
14
Amina
23 Jul 2016
1As we know that String is immutable. String class do not have reverse() method.
queries leading to this page
reverse string program in javarereverse strign in javajava string reversecreate jar that will accept string and return revers stringreverse a string in java i am a geekstrrev javareverse string in jvaareverse string java for loop manualcan we reverse a string in javareverse string function javareverse string without use funciton in javajava substring backwardshow to reverse string in javahow to get backword of string javareversing a string javahow to reverse a word in a string in javareversing a string inreverse a string in java using loopreverse words in a string javawrite a code to reverse a string in javajava string reverse functionreverse a string sololearn javaprint words of a string in reverse order javareverse strings in javareverse a string array in javareverse string array in javajava code reverse stringhow to write string reverse program in javareverse a string using sbrstringreverse a string in java 8what is string reverse in javareverse string in java charatreversing a string in javajava string reversereversing in javajava string array reverse methodhow to reverse the order of a string in javahow to put a string backwards in javajava code to reverse a stringreverse of string in javastring reverse method in javahow to reverse a string without using reverse function in javareverse string in a given string in javareverse 28 29 in string in javahow to reverse string in jvaareverse function of string in javareverse a string in java non void functionhow to revert a string javareverse a word in string in javareverse string javareverse a string in jvareversing words in a string javareverse string maverick in javahow to reverse a string wihtout using string mehthods in javareverse a parameter string javajava reverse string arrayenter the string to reverse using javahow to reverse string as a array in javareverse a string in java inplacejava revers stringjava string reverseejava program for string reversestring reversal in javamethod to reverse a string in javareverse in javajava reversing stringreverse a string in java sololearnwhy string does not have reverse in javafind reverse of string javareverse the string again in java without using functionsstring reverse in jaareverse string list javawrite a program to reverse string in javareverse string java 7string class reverse method in javastring reverse string in javahow can we reverse a string in javahow to reverse a string in java using inbuilt functionhow to revese a string in java 27reversing a string in java in a methodreverse a sstring in javastring reverse 28 29 in javamethod for reversing a string in javareverse a string program in javajava program to reverse a string without using another stringreverse a string in java using for loopjava method to reverse a stringstring reverse 28 29 in javastring reverse 28 29 method in javareverse string java 8 how to reverse a string in javareverse a string in java using charat java 3freverse string by words in javareverse string ajvaprint string in reverse order javareverse string in java without using functionwhat is reverse string in javahow to reverse in string in javareverse string in java using built in function in pythonreverse a string without reversing the words in javastring reverse 28 29 javareverse method for string in javahow would you reverse a string in javajava reverse string orderreverse string function in javareverse fun in string in javajava program to reverse words in a given string reverse string in array program in javastring inout and reversingreverse the characters in a string javareverse a word in a string in javareverse a string using charat in javajava string 5b 5d reversereverse string function jvareverse word javahow to reverse a string in java using for loopjava program to reverse string arrayrevers string in javareverse order string in javajava reversing a stringwhat is reverse of a string in javajava substring reversereverse a string 3a javastrin reverse in javareverse a string of words in javareverse strings javawrite a function to reverse a string in javareverse string array javareverse string words in javatreverse a string methodreversing string javainbuilt method to reverse a string in javareverse method in string javareverse a word of string in javajava progrsm to reverse a stringhow to reverse function string javajava 8 reverse string reverse in javastring reverse java methodreverse in java stringsubstring java reversehow do you reverse string in javahow to get the reverse of a string in javareverse method reverse is all the character in javareverse string method javajava reverse methodreverse string algorithm javahow to reverse a given string in javareverse string using for loop javareverse string using java streamsjava program to print string in reverse orderrevrse a string in javajava reverse the lettersreverse a string javato reverse a string in javahow to use reverse to apply to stringwhy we use reverse string in javareverse methods java reverse string javareverse the order of a string javastring reverse in java using functionstrng reverse i jaavareverse substring javajava reverse a stringreverse string in java without using built in functionhow to reverse a part of sub string in javahow to return the reverse of a string in javahow to reverse string in java 3fwap to reverse string in javawhat is the easy way to reverse a string in javahow ti reverse a strin javahow to write a reverse java methoddoes java has string reverse functionlogic of reverse string in javawrite a java program to reverse a string best way to reverse a string jaavhow to reverse a string in java 3freverse letters of a string in javastring reverse function in stringthe reverse method should take a string as an argument and return a new reversed version of the string how to string reverse in javajava string reverse import libraryreverse a string without using string function in javahow to reverse a string words in java without using reverse functionstr rev function in string in javareverse a string in java methodfunction to reverse a string in javahow to do reverse of string in javareverse a string in java without using reverse functionjava algorithm to reverse a stringreversing string in java program2 write a method that takes a string as an input and reverses the string this reserved result should be the output output reverse text javahow to reverse order of a string in javahow to revers string in javasubstring from reverse in javareverse string in java simple programhow to reverse string javainbuilt string reverse function in javajava 8 reverse string programjava string reversed 28 29java write a method string reverse orderinverser string javareverse a string in java efficientlychange reverse string in javareverse string in java 5cprogram to reverse a string in java without using functionreturn a string in reverse order javareverse string sentence in javahow to reverse a string and retrun in javajava program to reverse a string without using string inbuilt functionsololearn reverse a string javareversiong a string in javareverse the string in javajava reverse stringstring reverse in javareverse a string in java using inputrecverse stringjava program for reverse stringhow to reverse a string of character in javareversse method javaget reverse stringget reverse of string javastring rev in javastirng reverse javareverse words in a given string in javaprogram to reverse a string java reverse a words in a string in javareverse a srting in javareverse a java stringis there any in built function to reverse a string in javareverse string in java and return how to reverse a string javastring reverse function in javastring reverse syntax in javarevert string in javareverse words of a string in javarev javajava code for reversing the string and for concatenation of two stringsfor given string return a new string 2awith the reversed order of charactersjava print reverse of a namerevert text on a string java geeksforgeeksjava string invertjava reverse the stringreverse string in java functionreverse a string in java usinmethod to reverse string in javajava how to reverse a stringsubstring reverse javareverse a striong in javajava function to reverse stringhow to reverse a string in java without using functionwrite a program to reverse the string in javajav string reverse is samehow to print the string in reverse javastring reverse javastring reverse in javastring reverserevert string javahow many ways to reverse a string in javahow to print a string in reverse javahow to reverse string using for loop in javajava reverse words in stringreverse string in java with out build methodprogram to reverse a string in javamethod stringreverse that accepts a s string and return a reverse string javacode to reverse a string in javahow to reverse a string in java without using reverse functionstring reverse logic in javahow can we reverse a string 2c without using length functions in javareverse words in string javareversing a string javhow to reverse string in for loop javajava program to reverse a stringwhy is reverse method in java not used for stringreverse a string sentence in javareverse string in javastring reversein javareverse a string havawrite a program to reverse a string in javahow to reverse individual words in a string in javareverse method in java implementationreversing method string javainverts the string in memory reverse string in java using charatwrite a jave statement to reverse the given string 3fhow do you reverse a string in javahow to reverse the words in a passed in string javainvert string javatoreverse in javareverse string java chararthow to get a string in reverse javajava string class inverting stringjava how to revert a stringstr reverse in javareversing string in javais it possible to use reverse 28 29 on string javahow to reverse a string array in javahow to reverse a string in jaava inplacereverse text in a string javarever se string javahow to reverse string java with loopprint string in reverse in javafastest way to reverse a string in javastring reversestring rev javahow to reverse tostring 28 29 in javareverse a string using loops in javajava method for reversing stringstring reverse in java using char arrayreverse a string in java without using inbuilt functionstring get reverse javajava string reverse meyhodreverse a string in javastring reverse code in javapublic string reverse 28int index 29reverse order string for javareverse an array of string in javareverse a string in h 3djavareverse java stringfuction to reverse a string in javareverse funtion in string injjajvareverse words in a string in javainbuilt function to reverse a string in javastring reverse program in javajav string reversereverse order of a string javastr reverse javareverse method in javareverse string in java using for loophow to print reverse string in javawrite a program to reverse a string without using inbuilt function in javareverse string jva libraryreverse string in java collectionstring reverse without using inbuilt function in javahow to reverse string lettershow to reverse a string in javareverse th string in javastring reverse in java functionreverse string in java logicjava reversemake string backwards javajava reverse text in javareverse a string in java