Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java: How to reverse the words in a string

Java: How to reverse the words in a string
{filelink=12230}

import java.util.Stack;
import java.util.StringTokenizer;
public class Word_Inverse
{
  public static void main (String[] args)
  	{
	String str = "Welcom to tubedir.com";
	Stack  stack = new Stack();
	StringTokenizer strTok = new StringTokenizer(str);
	while(strTok.hasMoreTokens())
	{
    stack.push(strTok.nextElement());
	}
	StringBuilder str_reverse = new StringBuilder();
	while(!stack.empty())
		{
    str_reverse.append(stack.pop());
    str_reverse.append(" ");
		}
System.out.println("original string: " + str);
System.out.println("reversed string: " + str_reverse);
    }  
}

Users who found this page were searching for:

  • calculate the difference of days between 2 dates in perl
  • odd and even numbers using while in python
  • java program reverse words array
  • perl java hashcode
  • perl print line count
  • java reverse words in a string
  • java reverse words
  • python how to read bin file and print into structure
  • how to index the key value pair python
  • example in java how to reverese words

No comments yet.

Leave a Comment