String Reverse in Java...!

Answer Posted / anjani kumar jha

import java.util.*;

public class StringReverseWord {

private static void doStringReverseWord() {

String a = "Anjani ...................Kumar Jha";
Stack stack = new Stack();

// this statement will break the string into the
words which are separated by space.
StringTokenizer tempStringTokenizer = new
StringTokenizer(a);

// push all the words to the stack one by one
while (tempStringTokenizer.hasMoreTokens()) {
stack.push(tempStringTokenizer.nextElement());
}

System.out.println("\nOriginal string: " + a);

System.out.print("Reverse string: ");

//pop the words from the stack
while(!stack.empty()) {
System.out.print(stack.pop());
System.out.print(" ");
}
System.out.println("\n");
}
public static void main(String[] args) {
doStringReverseWord();

}

}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does the ‘static’ keyword mean? Is it possible to override private or static method in java?

563


How do you replace a string in java?

543


Is set ordered in java?

571


If an application has multiple classes in it, is it okay to have a main method in more than one class?

537


What is lastindexof in java?

547






What is a final class ?

602


What is function declaration?

526


What is the difference between Error, defect,fault, failure and mistake?

658


What is string array?

577


Does anyone still use java?

582


Why should we use singleton pattern instead of static class?

459


State the merge-sort principle and its time complexity.

572


What is an example of declaration?

523


What is the use of conditional statement?

562


What is pojo class in java?

537