Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

reverse string in java

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

reverse sentence in java

// INPUT: "you shall not pass"
// OUTPUT: "pass not shall you"
  
String s[] = "you shall not pass".split(" "); 
String ans = ""; 
for (int i = s.length - 1; i >= 0; i--) {
  ans += s[i] + " ";
}
System.out.println(ans);
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

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

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 in Java

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

java reverse a word

To reverse a word 

- Put all the letters in a stack and pop them out. 
Because of the LIFO order of stack, you will get the letters in 
reverse order.
Comment

reverse words in a string java

// Java Program to reverse a String
// without using inbuilt String function
import java.util.regex.Pattern;
public class Exp {
 
    // Method to reverse words of a String
    static String reverseWords(String str)
    {
 
        // Specifying the pattern to be searched
        Pattern pattern = Pattern.compile("s");
 
        // splitting String str with a pattern
        // (i.e )splitting the string whenever their
        // is whitespace and store in temp array.
        String[] temp = pattern.split(str);
        String result = "";
 
        // Iterate over the temp array and store
        // the string in reverse order.
        for (int i = 0; i < temp.length; i++) {
            if (i == temp.length - 1)
                result = temp[i] + result;
            else
                result = " " + temp[i] + result;
        }
        return result;
    }
 
    // Driver methods to test above method
    public static void main(String[] args)
    {
        String s1 = "Welcome to geeksforgeeks";
        System.out.println(reverseWords(s1));
 
        String s2 = "I love Java Programming";
        System.out.println(reverseWords(s2));
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: split email on dot java 
Java :: okhttp Updating Views on UIThread 
Java :: no main attribute in java android 
Java :: remove character stringbuffer 
Java :: Java create an object of the non-static class Reptile 
Java :: managa firebase users 
Java :: taking user input in array in java using constructor 
Java :: java object class 
Java :: Person[] people = in java 
Java :: java connect socket to POP3 
Java :: i have use tried catch but still prints exception java 
Java :: regex pattern to mathc IP address 
Java :: find if element is powers of 2 
Java :: do i have to import files from the same package in java 
Java :: success listener with Glide Android java 
Java :: public static void nPrintln(String message, int n) { 
Java :: javax.servlet.ServletException: javax.servlet.jsp.JspException: Missing message for key 
Java :: fly dfguyghj: Javascript 
Java :: public static void main(String args[]) { level input=new level(System.in); FirstPractice obj1=new FirstPractice(); obj1.loosing(1000); } 
Java :: leak canary 
Java :: edit data from database sqlite android 
Java :: android dynamically create layer-list with item and shape site:stackoverflow.com 
Java :: action media scanner scan file android 30 deprecated 
Java :: jdned 
Java :: stack java 
Java :: aspectj after returning 
Java :: call c function from java 
Java :: super class and concrete class in java 
Java :: java supress unchecked 
Java :: Java Program to Print Spiral Pattern of Numbers 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =