[algorithm] Reverse the ordering of words in a string

public class StringReverse {

  public static void main(String[] args) {

    StringReverse sr =new StringReverse();
    String output=sr.reverse("reverse this string");

    String substring="";
    for(int i=0;i<=output.length();i++)
        {
        if(i==output.length()){
            System.out.print(sr.reverse(substring));
            substring="";
        }else if(output.charAt(i)==' ' ){
            System.out.print(sr.reverse(substring+" "));
            substring="";

        }
        if(i<output.length())
        {
        substring+=output.charAt(i);}
        }

}

public String reverse(String str){
    char[] value=str.toCharArray();
    int count=str.length();
    int n = count - 1;
    for (int j = (n-1) >> 1; j >= 0; --j) {
        char temp = value[j];
        value[j] = value[n - j];
        value[n - j] = temp;
    }
    return new String(value);
  }
}

Examples related to algorithm

How can I tell if an algorithm is efficient? Find the smallest positive integer that does not occur in a given sequence Efficiently getting all divisors of a given number Peak signal detection in realtime timeseries data What is the optimal algorithm for the game 2048? How can I sort a std::map first by value, then by key? Finding square root without using sqrt function? Fastest way to flatten / un-flatten nested JSON objects Mergesort with Python Find common substring between two strings

Examples related to data-structures

Program to find largest and second largest number in array golang why don't we have a set datastructure How to initialize a vector with fixed length in R C compiling - "undefined reference to"? List of all unique characters in a string? Binary Search Tree - Java Implementation How to clone object in C++ ? Or Is there another solution? How to check queue length in Python Difference between "Complete binary tree", "strict binary tree","full binary Tree"? Write code to convert given number into words (eg 1234 as input should output one thousand two hundred and thirty four)

Examples related to string

How to split a string in two and store it in a field String method cannot be found in a main class method Kotlin - How to correctly concatenate a String Replacing a character from a certain index Remove quotes from String in Python Detect whether a Python string is a number or a letter How does String substring work in Swift How does String.Index work in Swift swift 3.0 Data to String? How to parse JSON string in Typescript