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

Write a java program to generate fibonacci series ?

582


What is string :: npos?

587


What is the full form of jpeg?

531


Who developed java?

586


Can we call thread start () twice?

527






Explain yield() method in thread class ?

629


What is a ternary operator in java?

549


Is the milky way in a void?

551


How do you convert an int to a string in java?

550


Does java map allow duplicates?

504


What happens when heap memory is full?

539


Can we extend singleton class in java?

558


What is the use of runnable interface?

629


What is a superclass?

937


Where is stringbuffer stored?

559