Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

reverse string in java

String reverse = new StringBuilder(string).reverse().toString();
Comment

reverse a string in java

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

how to reverse a string in java

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));
            }
    }
}
Comment

how to reverse a string in java without function

String reverse(String s) { 
   if(s.length() == 0) 
     return ""; 
   return s.charAt(s.length() - 1) + reverse(s.substring(0,s.length()-1)); 
 }
Comment

reverse a string in java

// 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);
}
Comment

Reverse a String in Java

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


   }

}
Comment

PREVIOUS NEXT
Code Example
Java :: java hello word 
Java :: space seperator in string in java 
Java :: how to clear text fields in java 
Java :: set look and feel system default java 
Java :: multiplication program java 
Java :: compare numbers in array in java 
Java :: map java 
Java :: get element in arraylist java 
Java :: java standard exception 
Java :: tomcat 9 default username and password 
Java :: quicksort for arraylist 
Java :: android maven dependency 
Java :: java toggle button get state 
Java :: write in text file android studio 
Java :: pyramid pattern program in java 
Java :: java program to remove duplicate words in a string 
Java :: how to create alert dialog in android studio 
Java :: how to get current time and date in android 
Java :: abstraction in java 
Java :: java string get ith char 
Java :: fixed length array powershell 
Java :: JsonArray get first Object 
Java :: lambda java 
Java :: button getsource 
Java :: print statement in java 
Java :: JFrame frame = new JFrame (); 
Java :: list java 
Java :: regular expression java 
Java :: wait method in java 
Java :: can i run script in ubuntu using java 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =