Check out example codes for "reverse a string in java". It will help you in understanding the concepts better.

Code Example 1

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

Code Example 2

As we know that String is immutable. String class do not have reverse() method.

Code Example 3

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

Code Example 4

//make a scanner object
Scanner input = new Scanner(System.in);

//take in an input string and store it inside a <String> variable
System.out.println("Enter the string: ");
String string = input.nextLine();

//convert string to character arraylist by first creating
//an array list for the characters in correct order
//and an array list for what we will use
//to store the characters in reverse order later in the code
ArrayList<Character> chars = new ArrayList<Character>();
ArrayList<Character> reversed = new ArrayList<Character>();

//put all the characters from string into chars arrayList
for (char c : string.toCharArray()) {
    chars.add(c);
}

//get the size of the arraylist
Integer length = chars.size() - 1;
Integer x = 0;

//loop all the elements in the array chars into reversed arraylist in reverse order
while(x < chars.size()) {
    reversed.add(chars.get(length));
    length -= 1;
    x += 1;
}

Code Example 5

// Java program to ReverseString using StringBuilder 
import java.lang.*; 
import java.io.*; 
import java.util.*; 
  
// Class of ReverseString 
class ReverseString 
{ 
    public static void main(String[] args) 
    { 
        String input = "Geeks for Geeks"; 
  
        StringBuilder input1 = new StringBuilder(); 
  
        // append a string into StringBuilder input1 
        input1.append(input); 
  
        // reverse StringBuilder input1 
        input1 = input1.reverse(); 
  
        // print reversed String 
        System.out.println(input1); 
    } 
}

Learn ReactJs, React Native from akashmittal.com