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

string reverse in java

String str = "Hello";
String reverse(String str){
  StringBuilder sb = new StringBuilder();
  sb.append(str);
  sb.reverse();
  return sb.toString();
}
Comment

java reverse string

// 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

String reverse in java

1)
String str = "Hello";
String result = "";

  for(int i = str.length()-1; i>=0; i--){
     result += str.charAt(i); // first solution, charAt method
 //  result += str1.substring(i, i+1); // first solution,  substring method
   }
   System.out.println(result);
}

Comment

String Reverse Program in Java.

// java program to reverse a word
  
import java.io.*;
import java.util.Scanner;
  
class GFG {
    public static void main (String[] args) {
        
        String str= "Geeks", nstr="";
        char ch;
        
      System.out.print("Original word: ");
      System.out.println("Geeks"); //Example word
        
      for (int i=0; i<str.length(); i++)
      {
        ch= str.charAt(i); //extracts each character
        nstr= ch+nstr; //adds each character in front of the existing string
      }
      System.out.println("Reversed word: "+ nstr);
    }
}
  
//Contributed by Tiyasa
Comment

String reverse in Java

StringBuilder sb1 = new StringBuilder("Mahmut");
        sb1.reverse();
        System.out.println(sb1); // tumhaM
Comment

PREVIOUS NEXT
Code Example
Java :: check if two lists are equal java 
Java :: java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider 
Java :: maximum number from random number in java 
Java :: JFrame change outline 
Java :: java local function 
Java :: android studio clear views of layout 
Java :: . Java Program to Delete the Specified Integer from an Array 
Java :: mettre caractère de string en majuscule java 
Java :: math.sin in java 
Java :: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 
Java :: java regular expressions 
Java :: Retrieve User information in Spring Security 
Java :: hangfire list recurring jobs 
Java :: t implements comparable 
Java :: sort a list in java according to last name 
Java :: java get number at the end of string 
Java :: fix nullpointerexception 
Java :: intersection of two arrays java 
Java :: selenium java control + enter 
Java :: java store data 
Java :: java arraylist initialize with 0 
Java :: getter in java 
Java :: java boolean data type 
Java :: Java Create a ByteArrayOutputStream 
Java :: unresolved reference activity_main 
Java :: android studio convert java to kotlin 
Java :: is it possible to declare two conditions in for loop in javascrip 
Java :: javax 
Java :: round int java 
Java :: method overriding java 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =