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:

  • strikethrough text java
  • ftp perl download
  • program on factorial in perl
  • calculate the difference of days between 2 dates in perl
  • java reverse words in a string
  • reversing words in string in java
  • python how to read bin file and print into structure
  • from BigDecimal to words
  • how to reverse a word in java
  • how to calculate factorial in perl

No comments yet.

Leave a Comment