Skip to content

Instantly share code, notes, and snippets.

@ShubhamS32
Created March 14, 2019 11:03
Show Gist options
  • Select an option

  • Save ShubhamS32/d068e7b014888bb5bc4b7b9e85f18e63 to your computer and use it in GitHub Desktop.

Select an option

Save ShubhamS32/d068e7b014888bb5bc4b7b9e85f18e63 to your computer and use it in GitHub Desktop.
To Reverse String without using String Buffer
package org.pre;
public class ReverseString {
public static void main(String[] args) {
// TODO Auto-generated method stub
String word="shubham";
char[] warray=word.toCharArray();
char[] farray= new char[warray.length];
System.out.println("Length :"+warray.length);
int k=0;
for(int i=(warray.length-1);i>=0;i--)
{
System.out.println(warray[i]);
farray[k]=warray[i];
System.out.println(farray[i]);
k++;
}
String reverseString = new String(farray);
System.out.println("reverseString : "+reverseString);
String rString = String.copyValueOf(farray);
System.out.println("RString :"+rString);
System.out.println(farray);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment