Hi Rahul,
First of all, don't be 2222 formal. All here r friends sharing thoughts & ideas.
Instead of
spoon feeding, i'll rather give u some hints :-
1. Read java.text.BreakIterator javadocs
2. Take a look at
Text Bound Demo 3. If u r not going for BreakIterator stuff then :-
After getting text of the document get it's char array and traverse back and forth to find the word boundaries. NOTE consider i18n issues and instead of checking for " " (space character) check whether the given character is space or not by Character.isWhiteSpace(char) method.
Note that the default BreakIterator instance assumes word boundary at every non letter and digit so there is high possibility that u may go for No. 3 option. NOTE that BreakIterator can be customized to suit any requirement.
Hope this will give u some dirn.