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

java Write a program to reverse an array or string

// Iterative java program to reverse an
// array
public class GFG {
     
   /* Function to reverse arr[] from
    start to end*/
    static void rvereseArray(int arr[],
                    int start, int end)
    {
        int temp;
          
        while (start < end)
        {
            temp = arr[start];
            arr[start] = arr[end];
            arr[end] = temp;
            start++;
            end--;
        }
    }    
      
    /* Utility that prints out an
    array on a line */
    static void printArray(int arr[],
                            int size)
    {
        for (int i = 0; i < size; i++)
             System.out.print(arr[i] + " ");
          
         System.out.println();
    }
 
    // Driver code
    public static void main(String args[]) {
         
        int arr[] = {1, 2, 3, 4, 5, 6};
        printArray(arr, 6);
        rvereseArray(arr, 0, 5);
        System.out.print("Reversed array is 
");
        printArray(arr, 6);
        
    }
}
 
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 :: copy elements of array in java 
Java :: java replace string case insensitive 
Java :: android toolbar menu align center 
Java :: collatz conjecture 
Java :: maven paper 
Java :: date minus date java 
Java :: java if or 
Java :: java nested loop 
Java :: java subscript numbers 
Java :: char to unicode java 
Java :: generate serial uuid with intelij 
Java :: android application subclass 
Java :: spring boot jackson infinite recursion 
Java :: findviewbyid in kotlin Just using id name . 
Java :: android java listview clean 
Java :: java delete column from csv 
Java :: java math power 
Java :: hello world! java 
Java :: dropdown menu with spinner dropdown icon color change in android 
Java :: parameterized constructor 
Java :: sorting java 
Java :: java print formatted string 
Java :: Program type already present: android.support.v4.app.INotificationSideChannel 
Java :: transpose of a matrix java 
Java :: reverse a string in java 
Java :: java what is at 
Java :: HOW TO PARSE a string into a number in java 
Java :: does constructor return any value java 
Java :: convert integer array to string array 
Java :: how to create a constructor in java 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =